-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template engine #3
Comments
I vote for a real template engine, cause PHP code in templates will lead to templates which contain too much logic. Twig would be a good choice it's simple and easy to understand - also for non programmers. And it covers the most common control structures like |
You should take a look at the For other functionalities like replacing text, formating/converting dates, timestamps, etc. I'd suggest a helpers.php with plain old functions inside. Just like some nice shorthands which can be used everywhere in the code.
Please define "too much logic". The only things we might need inside a template would be Even I know that Twig is simple I don't think that we need a full scale templating engine for these few things. Besides this I currently only see more or less advanced developers in the webgamers group, which know to keep logic out of the templates/views or at least as small as possible. And if there are other people contributing their stuff via pull-request we still can deny it if there is too much logic inside the templates/views. |
"too much logic" means that youre able to do some crazy things inside the template(e.g. call a method of an object, create new instance of a new class and so on) you can get some informations if you google for "logic less template engine" Mustache is one for example, you cannot define there even an else or elseif or if something === anything while in twig, you can even check for regular expressions.. |
well, PHP has many libraries and features and if you would use stuff like the SPL inside of a template, it would be too much logic. That's the problem with PHP as template language.
I don't like extract. In my approach I use ArrayObject + Closure Binding to have a new scope for the template. In case of extract the scope of the render() Method and the scope of the template would be the same one which means, that you could access stuff from the template object.
Twig supports functions, too :)
well, the big advantage of twig is, that it is extremely flexible (if you work with Symfony, you see how much we could do with it). The problem with mustache is, that we don't have features like template inheritance. |
well mustache is also extermly flexible and you dont need inheritance feature for templates, you can still reuse template parts with partials, but i dont want say anything against twig, iam not a part of that project anyways;) iam just against PHP templates |
mustache is great! +1 |
I am against mustache, cause this project is for beginners and beginners need some kind of logic in templates. Otherwise they will produce bad server side code (I think of storing pre rendered timestamps in database to reduce difficulty in displaying them., etc.). I know why mustache exists and appreciate its usage in well designed professional projects where every developer understands separations of concerns. But this project is meant to be an entry level one - so I would choose Twig rather than Mustache. |
i think, if the project would be for beginners, why the heck there is already a DI Container? beginners dont know why the need Depdency Injection ;) |
Since I made the first pull-req I was wondering how long it would take if someone come up with that issue and you're absolutely right about this. But this should be discussed in a separate topic because I personally came to the clue that DI is somekind of a tipping point. |
So where do you draw the line between 'beginner' and 'advanced'. Does a beginner know what a template engine is? And if the beginner uses the template engine... does he use it right and does he keep the logic out of the templates? |
A controller should never generate the html of the view.
I recommend a template engine to render templates and use the result as view.
If we don't use Twig, we could use PHP as engine.
I've implemented a simple template php templating engine which we may use: http://pastebin.com/j9vw9guD
The text was updated successfully, but these errors were encountered: