你的模板策略是什么? [英] What are your templating strategies?

查看:154
本文介绍了你的模板策略是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图开发自己的小框架。为此,我想阅读一些模板技术。我知道模板是一个非常复杂的主题,但知道一些策略可以帮助找到正确的一个。



请,如果你提到一个,不要写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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆