你的模板策略是什么? [英] What are your templating strategies?
问题描述
请,如果你提到一个,不要写smarty 例如。写一点关于它背后的概念。
让我开始一个想法:为了使事情变得简单,我的模板文件只是包含HTML的PHP文件。模板可能包括其他模板。数据通过$ data变量插入到模板中,$ data变量是包含模板所有数据的关联数组。
因此,在第一阶段,控制器执行一些动作并建立$数据数组。接下来,将包括适当的模板。
问题:模板可能不仅要包括模板,还可以包括控制器。即显示面包屑或菜单(背后有相当复杂的逻辑,太复杂,无法在模板中处理)。
有请查看网络演示文稿模式部分,特别是模板视图,转换视图,两步视图。对于像渲染面包屑或分页的东西,您可以使用查看帮助器模式。
I try to develop my own little framework. For this, I'd like to read up some templating techniques. I know that templating is a really complex topic, but knowing some strategies could help find the right one.
Please, if you mention one, don't just write "smarty" for example. Write a little about the concept behind it.
Let me start with an idea: To make things simple, my template files are just PHP files that contain HTML. Templates may include other templates. The data is inserted into the templates through a $data variable, which is an associative array containing all the data for the template.
So, at the first stage a controller performs some action and builds up that $data array. Next, the appropriate template will be included.
Problems: A Template might have to include not only templates, but also controllers. i.e. displaying a breadcrumb or menu (with fairly complex logic behind, far too complex to be handled in a template).
Have a look at the section Web Presentation Patterns, especially Template View, Transform View, Two-Step View. For stuff like rendering breadcrumbs or pagination, you can utilize a View Helper pattern.
这篇关于你的模板策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!