MK_*_*Dev 2 php templates phptal template-tal
在过去的几天里,我一直在玩PHPTAL.总的来说我非常喜欢它.比我调查的其他大多数人都要容易得多.不过,我有一个特别的问题.
这是问题所在.我试图嵌套两个模板.假设InnerClass有这个模板:
<div>Hello World!</div>
Run Code Online (Sandbox Code Playgroud)
OuterClass具有以下模板:
<div tal:content="myVar">This text should be replaced with the HTML above.</div>
Run Code Online (Sandbox Code Playgroud)
InnerClass还有一个名为render()的方法,它实质上调用了themplate的execute()方法并返回内容.所以我在外类中这样做:
$template->myVar = $innerClassObject->render();
Run Code Online (Sandbox Code Playgroud)
然后,我显示OuterClass的内容.问题是内部类的呈现HTML被转义,我看到">"和"<"而不是实际的标签.似乎myVar在显示内容之前完全转义.
由于这种方法不起作用,嵌套PHPTAL模板的最佳方法是什么?我认为它是可能的,它只是缺乏我的知识,所以任何输入都是值得赞赏的.
如果要在模板中插入任意标记,请使用structure
关键字:
<div tal:content="structure variable_that_contains_html"/>
Run Code Online (Sandbox Code Playgroud)
但是如果你想在另一个模板中嵌入一个PHPTAL模板,那么使用宏:
macros.xhtml:
<div metal:define-macro="greeting">Hello World!</div>
Run Code Online (Sandbox Code Playgroud)
page.xhtml:
<body><tal:block metal:use-macro="macros.xhtml/greeting"/></body>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1270 次 |
最近记录: |