SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 62
Thread: templated if's
-
Dec 21, 2005, 02:13 #26
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
You need basic looping and a basic conditional construct. That's all, the rest can be in a view helper. Do you disagree with that? If you do, how would you handle conditional HTML?Dagfinn Reiersøl
PHP in Action / Blog / Twitter
"Making the impossible possible, the possible easy,
and the easy elegant" -- Moshe Feldenkrais
-
Dec 21, 2005, 06:22 #27
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dagfinn
As with every arcitechtural choice, separating presentational logic from the view is a complication, and thus has a cost. If you don't need it, it will be baggage. The benifit of separating them is a higher degree of decoupling. In this case, one concrete benifit is, that the template-programmer needn't know how to write presentational code. Eg. the HTML-dude doesn't need to touch the PHP.
I haven't really got the time to get academical, but Fowler has a nice article about separating the presentational logic from the view. It's mostly concerned with traditional GUI's, but I suppose the conclusions could be projected onto a web-application.
-
Dec 21, 2005, 07:13 #28
There is also the WACT method of having logic within the template
http://www.phpwact.org/tag/core/default, thou again WYSIWYG editors probably would not like it.
-
Dec 21, 2005, 09:37 #29
Originally Posted by kyberfabrikken
Originally Posted by kyberfabrikken
The cost of seperating the two is that you now have logic without any context; you'll need to have both files open to make any meaningful changes to either. And since they're highly dependant on each other, you're not really promoting reuse. So this is an area where I don't think the benefits are worth it.
Originally Posted by kyberfabrikken
I think most of the people arguing that the template should have no logic at all are doing so because it can be a slippery slope, which leads to things like Smarty, basically providing all of php to the templates. In other words, that it's hard to maintain MVC seperation once you start allowing logic in the templates themselves. But it is possible provide useful amount of logic without breaking the seperation; you might want to have a look at this article http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf , which explains a very powerful templating system that provides just that.
-
Dec 21, 2005, 10:05 #30
Originally Posted by kyberfabrikken
Let's think rationally about it. When presentational logic is allowed in the templates, then the only connection between the controller and the view is the data for the template, ie, the template variables.
If you move presentation logic into the controller, now your view is tied into the controller on the data AND the presentation logic... how exactly does that qualify as a higher degree of decoupling?
I'm assuming you have the presentation logic in the controller, which I think is what you said earlier, but I don't exactly recall
-
Dec 22, 2005, 00:24 #31
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Dagfinn Reiersøl
PHP in Action / Blog / Twitter
"Making the impossible possible, the possible easy,
and the easy elegant" -- Moshe Feldenkrais
-
Dec 22, 2005, 02:14 #32
- Join Date
- Dec 2005
- Posts
- 29
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:<block id="is5"> A is equal to 5 </block>
Code:<!-- If foo = 1 --> <p>Foo is 1</p> <!-- EndIf foo -->
So if I create a value object of some kind from db data, this object is directly related to that of its source...
But then in when it comes to displaying page dependent of the nature of this objects properties... where does the above singular value get defined, most likely some kind of helper (if not in the controller ?) all that just because one would have two write a template language to handle
Code:<?php if (in_array($tpl['obj']->getType(), array('a', 'b', 'c'))) { ?> <span>hey</span> <?php } ?>
-
Dec 22, 2005, 05:11 #33
I like the idea of using a state machine for controllers, and using the final state of the controller for picking the which part of the template to use. So a form controller could have final states of new, invalid, and accepted, and 3 or less subtemplates for it.
Still would need some method of presentation logic tho, for this like alternating row colours on tables.
-
Dec 22, 2005, 07:04 #34
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dagfinn
Originally Posted by 33degrees
Perhaps as a rule of thumb we could say that choosing whether to show something or not should be decided from the controller, while choosing how to show something should be decided by the template.
To stay with the negative numbers, this is fine :
Code:You balance is : <if condition="$balance < 0"> <span style="color:red">$balance</span> <else> $balance </endif>
Code:You balance is : <if condition="$balance < 0"> <span style="color:red">$balance</span> <p>Your account is overdrawn, please insert some money.</p> <else> $balance </endif>
Originally Posted by 33degrees
It may be an un-supported claim, but I think that thoose HTML-dudes will prefer custom tags, which hides the implementational details, over in-template logic.
-
Dec 22, 2005, 08:01 #35
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
which hides the implementational details, over in-template logic.
That is also benifitial to WYSIWYG editors, in that those tokens are displayed much like the rest of the HTML markup; Web designers should not concern themselves with application logic
-
Dec 22, 2005, 14:21 #36
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
You example of not having the text of the error message in the template is a good one. I think moving error message text to the Controller is a bad thing. It does not belong there and just adds one more place you have to make changes to presentation.
Regarding the Controller, I think a good rule of thumb would be that you should be able to make most (and even large) changes to the content of the presentation, whether contained in the View or Model, without having to touch the Controller.Christopher
-
Dec 23, 2005, 01:25 #37
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
PHP Code:$numberclass = ($balance >= 0 ) ? 'positive' : 'negative';
Code:<span class="$numberclass">$balance</span>
Code:.negative { color: red }
-
Dec 23, 2005, 01:42 #38
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dagfinn
The problematic part of kyberfabrikken's code was this:Code:<p>Your account is overdrawn, please insert some money.</p>
Christopher
-
Dec 23, 2005, 06:13 #39
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That example was probably rather weak, and I haven't completely thought it through, admittedly. I'll have to ponder over that during the hollydays.
Originally Posted by arborint
-
Dec 23, 2005, 07:57 #40
Originally Posted by kyberfabrikken
That could depend on the application as well. That kind of error message *could* be an application error, but without any kind of context, I'm forced to take it for what it is, which in that case, I think the decision to show a message like that or not is entirely presentational. It is a business decision as well, but it belongs to the business of the business using the application, not to the business of the application itself (unless the application does have business in that, but again without context I will assume not).
-
Dec 23, 2005, 09:22 #41
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by arborint
Code:<span class="positive" tal:attributes="class numberclass" tal:content="balance">2043</span> <span class="negative" tal:replace="">-2043</span>
Code:<span class="positive">2043</span> <span class="negative">-2043</span>
Code:<span class="negative">-4000</span>
tal:attributes overrides the value of the class attribute, setting it to the value of $numberclass, in this case "negative"
tal:content replaces "2043" with the value of $balance, in this case 4000.
tal:replace in the second <span> removes the entire second <span> (=replaces it with an empty string)
-
Dec 23, 2005, 12:52 #42Regarding the Controller, I think a good rule of thumb would be that you should be able to make most (and even large) changes to the content of the presentation, whether contained in the View or Model, without having to touch the Controller.
Getting back to templates, I think it's perfectly acceptable to have logic inside the templates, but I can understand the objections to that. The answer then, is to split the View layer into two, with the template containing the presentation data, and a helper class containing the presentation logic. In fact, one could split up the view layer even more, with logic in the Helper, markup in the Template, presentation in .css files, behavior in .js files, and the actual non-model text in some kind of internationalization module.
-
Dec 23, 2005, 15:18 #43
- Join Date
- Apr 2003
- Location
- PA
- Posts
- 518
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm a huge fan of phpBB's template system. Comes with phpBB, and if I understand correctly (based on the comment in the file), you are free to use it as you wish for other applications.
-
Dec 23, 2005, 15:24 #44
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
Originally Posted by 33degrees
Christopher
-
Dec 23, 2005, 15:43 #45
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
I'm not sure I have a clear rule about where the View/Controller division is, but I find that reality usually sets if for me. The View, for me, is about creating the presentation given all the data provided. And I know in clear-cut cases that when there is a request to change a View I talk to a designer; when there is a request to change a Model I talk to some business department. That makes my job to show the business department's data in the way the designer wants it.
I have found that if I keep the designer in the Template and out of the View code I am happier. Likewise I find that if I keep the business depts. on their side of Gateways and Mappers then I am happier too. Happiness == Changes are not painful.
In parallel with the above, when I am dealing with the designer I prefer to only make changes to the View code; and likewise when I am dealing with a business dept. I prefer to only make changes to the Model code. If the above does not happen (and I have to muck with Controller code) then I usually try to refactor.
That's more of a process influenced definition than a functionality division.Christopher
-
Dec 23, 2005, 18:56 #46
Originally Posted by arborint
-
Dec 23, 2005, 21:35 #47
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
Originally Posted by 33degrees
Christopher
-
Dec 24, 2005, 04:13 #48
- Join Date
- Aug 2005
- Location
- South Africa
- Posts
- 185
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by arborint
For my current purposes I have managed to get away with having a controller, model and template (which in my case is the view then). I am just exploring when one would actually need the combo of creating a view that incorporates template/s.
--
lv
-
Dec 24, 2005, 08:33 #49
View code is all about generating presentation from base model. An extreme example which I'm developing still atm is generating charts, using inline svg.
http://ren.dotgeek.org/ex/example.php
[Requires FF1.5, a recent version of Opera (8.5 or 9 iirc), or IE with Adobe SVG Viewer plugin, apparently Safari nightlies have added SVG support so possibly could work in that too.]
-
Dec 24, 2005, 10:08 #50
Originally Posted by arborint
Originally Posted by arborint
Bookmarks