PHPTAL 和嵌套模板。可能的?
最近几天我一直在玩 PHPTAL。总的来说我真的很喜欢它。与我研究过的大多数其他人相比,它更容易进入。不过,我有一个特殊的问题。
问题就在这里。我正在尝试嵌套两个模板。假设 InnerClass 有这个模板:
<div>Hello World!</div>
OuterClass 有以下模板:
<div tal:content="myVar">This text should be replaced with the HTML above.</div>
InnerClass 还有一个名为 render() 的方法,该方法本质上调用了emplate 的execute() 方法并返回内容。所以我在外部类中执行此操作:
$template->myVar = $innerClassObject->render();
然后,我显示外部类的内容。问题是内部类的渲染 HTML 被转义,我看到“>”和“<”而不是实际的标签。看起来 myVar 在其内容显示之前就被完全转义了。
既然这种方法行不通,那么嵌套 PHPTAL 模板的最佳方法是什么?我认为这是可能的,只是我缺乏知识,所以任何意见都会受到赞赏。
I've been playing around with PHPTAL for the last couple of days. Overall I really like it. It's been much easier to get into than most others I've looked into. I am having one particular problem, though.
Here's the issue. I am trying to nest two templates. Let's say InnerClass has this template:
<div>Hello World!</div>
OuterClass has the following template:
<div tal:content="myVar">This text should be replaced with the HTML above.</div>
InnerClass also has a method called render(), which essentially calls themplate's execute() method and returns the content. So I do this in the outer class:
$template->myVar = $innerClassObject->render();
I, then, display the content of the OuterClass. The problem is that the rendered HTML of the inner class comes escaped and I see ">" and "<" instead of actual tags. It seems that myVar is completely escaped before its content is displayed.
Since this approach does not work, what is the best way to nest PHPTAL templates? I assume it's possible and it's just lack of knowledge on my end, so any input is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在模板中插入任意标记,请使用
struct
关键字:但如果您想将一个 PHPTAL 模板嵌入到另一个模板中,请使用 宏:
macros.xhtml:
page.xhtml:
If you want to insert arbitrary markup in a template, then use
structure
keyword:but if you want to embed one PHPTAL template in another, then use macros:
macros.xhtml:
page.xhtml: