Page 3 of 4
Re: Who wants to have a template engine discussion? :)
Posted: Thu Jan 22, 2009 1:37 pm
by sergio-pro
Ok, if Date object id custom object that compares in isEqual only date parts (without time) - It probably will work. By why not to mention it somewhere?
The error is $days is never incremented.
Re: Who wants to have a template engine discussion? :)
Posted: Thu Jan 22, 2009 1:45 pm
by sergio-pro
Your query can be of any complexity. What I say is that joining with 30 date rows is not a very expensive task. If everything is so bad, it wont make it much worse.
Here is an example of method calls from smarty:
Code: Select all
{* access our registered object *}
{foobar->meth1 p1='foo' p2=$bar}
{* you can also assign the output *}
{foobar->meth1 p1='foo' p2=$bar assign='output'}
the output was {$output}
{* access our assigned object *}
{$myobj->meth1('foo',$bar)}
Re: Who wants to have a template engine discussion? :)
Posted: Thu Jan 22, 2009 1:51 pm
by Eran
joining with 30 date rows is not a very expensive task
You would be right if it's a const join - but joining using an aggregate date function (for the partial match - which can't be indexed) against a table of millions of event rows is expensive.
Code: Select all
{* access our registered object *}
{foobar->meth1 p1='foo' p2=$bar}
{* you can also assign the output *}
{foobar->meth1 p1='foo' p2=$bar assign='output'}
the output was {$output}
{* access our assigned object *}
{$myobj->meth1('foo',$bar)}
For me, being unfamiliar with smarty syntax - this looks almost like another language. How maintainable are your scripts to non-smarty programmers would you believe? even though I'm using a framework, it's still PHP inside. As long as you are familiar with the concepts and know PHP well enough, you would do fine with my code.
Re: Who wants to have a template engine discussion? :)
Posted: Thu Jan 22, 2009 1:59 pm
by sergio-pro
You dont show millions of events in a calendar - dont you?
So, at first you filter only those, that belong to current month (+other 6 joins). And only those rows (their number should be reasonable) you join with dates. With good structured query it should be ok.
If you dont like smarty syntax - you can use another template engine, or create your own.
Template language syntax is much easier to learn than php.
Re: Who wants to have a template engine discussion? :)
Posted: Thu Jan 22, 2009 2:12 pm
by Eran
If you dont like smarty syntax - you can use another template engine, or create your own.
Template language syntax is much easier to learn than php.
Whoa there..

I already know PHP! so why would I or any of my team members would want to learn an alternative syntax that provides limited capabilities? this would happen if there was a distinct advantage to it - the syntax itself is definitely not an advantage, it's another barrier to cross.
You dont show millions of events in a calendar - dont you?
So, at first you filter only those, that belong to current month (+other 6 joins). And only those rows (their number should be reasonable) you join with dates. With good structured query it should be ok.
Yes, obviously I use additional filters - the query performance would depend greatly on which of those would be applied first. In any case it would be a non indexed condition, which you really want to avoid on large tables.
This doesn't matter anyway, as the result array would still be two dimensional and would have to be sorted via PHP (I don't really see the advantage of the date join).
Re: Who wants to have a template engine discussion? :)
Posted: Fri Jan 23, 2009 8:51 pm
by josh
pytrin wrote:Whoa there..

I already know PHP! so why would I or any of my team members would want to learn an alternative syntax that provides limited capabilities? this would happen if there was a distinct advantage to it - the syntax itself is definitely not an advantage, it's another barrier to cross.
Why would someone with a car learn to ride a bike? I dont know but they do. Maybe PHP is overkill / not secure enough for some purposes.
Re: Who wants to have a template engine discussion? :)
Posted: Fri Jan 23, 2009 8:54 pm
by allspiritseve
jshpro2 wrote:Why would someone with a car learn to ride a bike? I dont know but they do.
Because you don't have to pay for gas

Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 12:11 am
by Christopher
jshpro2 wrote:Why would someone with a car learn to ride a bike? I dont know but they do.
You continue to out-do yourself!!!

Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 8:43 am
by kaisellgren
pytrin wrote:I have an example which I think would be hard to replicate easily with a template engine. Suppose I want to draw a monthly calendar:
Code: Select all
<table>
<tr>
<?php
$rows = $this -> rows; //A result set of database events sorted by date
$row = current($rows);
$days = 1;
$html = '';
foreach($monthDays as $date) { //$monthDays is an array of date objects, once for each day in the month
if($days % 7 == 0) { // Split weeks into rows
$html .= '</tr><tr>';
}
$html .= '<td>' . $date -> toString('d');
while($row !== false && $date -> isEqual($row['date']) ) { //Advance the result set only for matching dates
$html .= '<br />' . $row['event'];
$row = next($rows);
}
$html .= '</td>';
}
echo $html;
?>
</tr>
</table>
The part which I think would be hard to implement in a template engine would the while loop with the dependent logic. You could claim that this could be abstracted outside using a view helper or something similar, but what if it only appear in one view? should I abstract everything even if there is no other need except to fit in a template engine?
I used to code like that. Putting HTML inside PHP, but that is just something so unversatile. Nowadays I put everything presentation like content may it be HTML, XML, JS, ... into the template and I let PHP to parse the results and then PHP will create the layout based on its results and template structure.
In my opinion, we should completely separate the logic and the presentation. Think about Wordpress. It is so popular yet it has ugly themes. Why? Because most theme designers do not know how to make themes for Wordpress. It is simple for us, but not for graphics artists and I know this based on experience since I am a graphics artist myself, but I also happen to know how to code.
We can always have presentation (or part of it) in our logic, but it always comes with a price. It is not easily extended. Think about that HTML table you used above, what if we are to create a template that works faster for mobile phones? Would you create a new version of your code and rewrite all just, because you did not separate the presentation?
I am not saying this or that is wrong or right. There are things that some people do not need. Sometimes it's just cool to have presentation in logic or the other way around. If your presentation is simple like they usually are. I really doubt most of us here have been making layouts that require CSS3, or making layouts for Nokia cellphones, etc. If the layouts are simple and if the creators of representations know PHP then it's not a big deal. SImply put I think it is pointless to argue about whether having logic or representation separately is good or not. Shall we argue which side of a bread is the right side to put butter on it?
There is no de facto standard. There is no ultimate solution. We have to define what we need, what we have and what we are capable of doing. And only then we shall find the ideal approach for ourselves that might not be suitable for others.
Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 8:54 am
by Eran
We can always have presentation (or part of it) in our logic, but it always comes with a price. It is not easily extended. Think about that HTML table you used above, what if we are to create a template that works faster for mobile phones? Would you create a new version of your code and rewrite all just, because you did not separate the presentation?
No, I would just need to create a separate template for the mobile device... not sure what you are trying to say, if you need to create different markup for mobile and desktop browsers, you would need separate templates. The logic of fetching the events is not presentational and is not present here - that doesn't change.
Actually, your example just strengthens my argument - if the presentational logic of creating the table structure would have been encapsulated in the model or any other non-view scopes, I would have needed to change it there - just for presentational purposes.
Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 9:11 am
by kaisellgren
pytrin wrote:We can always have presentation (or part of it) in our logic, but it always comes with a price. It is not easily extended. Think about that HTML table you used above, what if we are to create a template that works faster for mobile phones? Would you create a new version of your code and rewrite all just, because you did not separate the presentation?
No,
I would just need to create a separate template for the mobile device... not sure what you are trying to say, if you need to create different markup for mobile and desktop browsers, you would need separate templates. The logic of fetching the events is not presentational and is not present here - that doesn't change.
What am I missing - you said you are creating a separate template for the mobile device. A template. I thought its within your application since you are not using template engines.
So you are using template engines after all
pytrin wrote:Actually, your example just strengthens my argument - if the presentational logic of creating the table structure would have been encapsulated in the model or any other non-view scopes, I would have needed to change it there - just for presentational purposes.
If the presentational logic of creating the table structure is not in a template - then if someone needs to produce a WAP version of the table, XHTML, XML, XSLT, whatever - he would need to change your actual code and most often graphics artists can not do it (99% chance). I am confident this is fair enough for your purposes, but not for everyone's.
Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 9:22 am
by Eran
What am I missing - you said you are creating a separate template for the mobile device. A template. I thought its within your application since you are not using template engines.
So you are using template engines after all
I am using a templating system, just not in the sense that Ninja and sergio_pro are talking of. This templating engine is merely a separate scope for parsing PHP files, with some extendability / helper functionality (namely, I'm using Zend_View). This kind of templating is what I'm arguing is the best kind - using PHP as the tamplating language, and not some obscure dialect of it.
If the presentational logic of creating the table structure is not in a template - then if someone needs to produce a WAP version of the table, XHTML, XML, XSLT, whatever - he would need to change your actual code and most often graphics artists can not do it (99% chance). I am confident this is fair enough for your purposes, but not for everyone's.
Exactly my point!

sergio_pro was trying to convince me that this kind of code should go somewhere, since it is too complicated for a template. I'm arguing that since this code is presentational in nature, it should be in the template, and that is only possible if the template can use PHP as is.
Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 9:40 am
by kaisellgren
pytrin wrote:I am using a templating system, just not in the sense that Ninja and sergio_pro are talking of. This templating engine is merely a separate scope for parsing PHP files, with some extendability / helper functionality (namely, I'm using Zend_View). This kind of templating is what I'm arguing is the best kind - using PHP as the tamplating language, and not some obscure dialect of it.
Good. I honestly think you are doing the right way. I am basing my thoughts on the text you have written earlier about your project. You have a team of coders and they can handle your application along with its presentations. But you should realize that this kind of template engine talk does not cover all people on this earth. Trust me, there are so many branches in this area (presentation) and we can not make all-in-one solutions here.
pytrin wrote:Exactly my point!

sergio_pro was trying to convince me that this kind of code should go somewhere, since it is too complicated for a template. I'm arguing that since this code is presentational in nature, it should be in the template, and that is only possible if the template can use PHP as is.
I understand. A well formed template system can always produce the results as long as the PHP script itself is capable of producing those results. The template is limited to your main application - if it isn't, by which I mean it's even more limited, then your templating system smells. Let's say you create a table of information. The template must be able to produce it in XML, HTML, and so on. It makes little point of having templates if you need to change your actual application to work with different standards.
Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 12:25 pm
by josh
allspiritseve wrote:Because you don't have to pay for gas

Hah well w/ smarty I don't have to pay for stolen CC#s after my designer experiments with mysql_query()

Re: Who wants to have a template engine discussion? :)
Posted: Sat Jan 24, 2009 1:29 pm
by Luke
I have a lot of people going through the templates in my code. We have several designers, and the CEO who thinks he's a programmer going through them. When I allow them to just freely sprinkle php throughout my templates, I quickly end up with this:
Code: Select all
<?php
$alljobs = get_jobs();
?>
<h3><?php mysql_query("SELECT header FROM pages WHERE pagename = '" . $this->pagename . "'"); ?></h3>
<?php $date = date("m-d-Y"); ?>
<h4><?= $date ?></h4>
<?php foreach ($alljobs as $job) { ?>
<?php $people = get_people_by_job($job); ?>
<h5><?= ucwords($job) ?></h5>
<?php foreach ($people as $person) { ?>
<p><?= $person->name ?></p>
<?php } ?>
<?php } ?>
I don't like giving the ability to freely do whatever they want in the template. I much prefer the template engine in this case. Sure, when I'm doing projects on my own, it makes sense to just use php as the template engine. I think that's why I've always preferred not to use a template engine... because I worked by myself. Now I have to work with people who really have no clue about good practices, and I don't have the time to educate them. I have deadlines.