Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Why a templating language ???


Reply


8 Posts   1584 Views

Avatar
teejay

Community Member, 63 Posts

15 February 2010 at 6:06pm

I am soooo over it. We are developing in PHP, so is there reason to invent the wheel new. There is absolutly no benefit to use a pseudo language. It might help when u have simple structures. It is just pain in the ass to create douple efford to do extremly easy things like a counter. I know there is a pattern which says separate code from design. But when u think of it even this templating language creates logic. Today I just wasted an hour or more to provide template functions to provide me with a counter number. These number is not only a counter is goes over 2 record sets because the template shows me a list seamless for more then one records sets.

ul
control Bla1
li
end_control
control Bla2
li
end_control

what i have to do now is i need to double the efford cause i need to create functions which do exactly the same (loop) again just for counting.
double the db queries and so on. Pls explain me any good reason in respect of usability, usage, performance and more.

Just by the way, this is not an anti silverstripe thread, I love silverstripe, dont get me wrong but sometimes its just pain to do a simple thing on the hard way.

Avatar
Willr

Forum Moderator, 5513 Posts

15 February 2010 at 6:38pm

Edited: 17/02/2010 3:49pm

There is absolutly no benefit to use a pseudo language.

I disagree. I have worked with many a wordpress theme (which you can use php in) and very very quickly and easily a developer can turn it into a pretty horrid thing to try and follow with PHP nested with HTML and complex logic in the template. Sure its easy to build and flexible but it enables developers to take a some what lazier approach to structuring their code. SilverStripe tries to separate as much logic into your models, controllers as possible.

The template engine is pretty simple and there is a movement to basically rewrite it one day (Hamish wrote this to help with it http://github.com/hafriedlander/php-peg). I personally love the clear and conciseness that the template gives you and sure some things would be great (and I know these would be on the cards when SSViewer to tackled) is things like passing $Foo('Bar', 'Baz', 'Boo'), doing like $Up.Value, $Up.Up.Value to make it easier to traverse controls and some slightly more complex conditionals would be good but apart from those I don't really 'miss' anything in the templates that can't be done somehow.

Avatar
teejay

Community Member, 63 Posts

15 February 2010 at 7:52pm

I agree that this will happen for few cases. I love to separate my code as well I would never use a template to do things what should be done in my controller or model I worked long enough in that business to learn that. The issue is that u really need to know silverstripe to come around obviously trivial issues. Today i learned about the merge function. Which helped me with that issue !

I agree with having it clean, but more functions would be highly appreciated. I would love silverstripe more if everything of that what u have said becomes reality :)

Avatar
banal

Community Member, 901 Posts

15 February 2010 at 8:01pm

I totally agree with Willr here.
There are several benefits in using a template language. For one there's the fact, that if somebody knows HTML and CSS, he can design templates for SilverStripe. He doesn't have to know PHP, just learn the basic syntax and rules of the template language.
Also, when using PHP in the View, it's tempting to add some logic there that would actually belong to the controller or model. If you (or somebody else) comes back for an update of the site several months later, you'll curse yourself because you search several files to find out why stuff happens.

I for one never considered the template-language as a limitation. It enforces good design and I'm also glad I don't have to debug html-php mixes, be it at work or here on these forums ;)

Avatar
teejay

Community Member, 63 Posts

15 February 2010 at 8:12pm

Edited: 15/02/2010 8:16pm

I mean what ssviewer does is nothing more than replacing strings with php code like <?php if() {} ?> compared to <% if ?? %> this is not so much different. If u follow the pattern of separation stricltly u would never mix up business logic with template and design procedure. Of cause some developer would be tempted to do so, but thats just their problem. PHP itselft was invented to be a templating language. In my point of view, and from the development view there is no need for a templating language, cause u replace text with text and create overhead. But anyway this thread was created just because I was extremly frustrated with and issue which isnt one in the normal php world.

edit:

and to be honest Designer will never write the the templating logic for u this is absolutely no argument. Or let me say I have never met one who was interested at all in learning something what hes zero interested in !

Avatar
Hamish

Community Member, 712 Posts

16 February 2010 at 8:13am

"I mean what ssviewer does is nothing more than replacing strings with php code like <?php if() {} ?> compared to <% if ?? %> this is not so much different."

It does a lot more than that, but effectively it whitelists a very limited subset of code and provides accessors into your model. Which is the point, really.

"Of cause some developer would be tempted to do so, but thats just their problem."

Very rarely does one developers problem remain only their problem. If you can enforce good practice - which is partly the goal of any framework - then why not?

"In my point of view, and from the development view there is no need for a templating language, cause u replace text with text and create overhead."

The replacements only happen while the template manifest is being built. During execution the resulting manifest is evaluated as PHP - so what overhead are you're talking about? Do you mean the extra coding time? If you're seperating your view correctly you'd have to do this anyway?

"to be honest Designer will never write the the templating logic for u this is absolutely no argument"

There are plenty of designers with some knowledge of HTML/CSS and just enough PHP to get themselves into trouble. By giving designers only the tools they require to create a template, there is no risk of them doing something dangerous. If there is some functionality that they need that they can create with that code set, they go to the programmer.

Avatar
teejay

Community Member, 63 Posts

16 February 2010 at 2:00pm

Edited: 16/02/2010 2:02pm

The replacements only happen while the template manifest is being built. During execution the resulting manifest is evaluated as PHP - so what overhead are you're talking about? Do you mean the extra coding time? If you're seperating your view correctly you'd have to do this anyway?

U parse a template file replace the content and process it, I might be wrong but it produces the overhead of parsing (parseTemplateContent) the content . But anyway I never intended stepping on someones food, its just a discussion about the sense of templating engines. Using parse able phtml files as view files reduces file processing time on top, its maybe just my restrictive thinking.

I think I said that before I like silverstripe I just always wondered why there is a need of templating engines. Just a heads up for the developers of silverstipe, I worked lately on a ezPublish project and compared to that silverstripe is dream and much quicker to develop for, so pls dont see this discussion as criticism.

I worked lately or actually for a longer time with ZF and we never had issues or missed a templating system. It is just the matter of your quality assurance ur coding standards. If u work in a team u can ensure a certain quality of code just by reviewing others code and refactoring, but u have to do that continuously. Obviously it depends on the size of your team.
If u decide to build web apps after the MVC pattern then u have to follow it, if u dont u will lie to yourself and it wont bring u a step forward. That are just my 3 cents.

Avatar
Pigeon

Community Member, 243 Posts

17 February 2010 at 1:15pm

U parse a template file replace the content and process it, I might be wrong but it produces the overhead of parsing (parseTemplateContent) the content

The point i think [url=http://www.silverstripe.org/ForumMemberProfile/show/1763]Hamish[/url] was trying to make is that the templates are parsed once and then cached (in you tmp directory or silverstripe-cache folder if you have one) and so on a typical page load, there is no overhead induced by the templating engine. It is only on first call of a template or when ?flush is used that there is overhead due to the template parser.

MVC is an incredibly good model to work to an it helps enforce good coding. Ok, you might be good enough to not require the enforcement, but many developers see the clear separation as a help, not a hindrance. Like [url=http://www.silverstripe.org/ForumMemberProfile/show/1763]Hamish[/url] said, frameworks are meant to enforce good practice.