PHPTAL and nested templates. Possible?
I've been playing around with PHPTAL for the last couple of days. Overall, I really like it. It was much easier to hit than most of the others I have studied. However, I have one specific problem.
Here's the problem. I am trying to nest two templates. Let's say InnerClass has this pattern:
<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 the executeplate () method and returns the content. So I am doing this in an outer class:
$template->myVar = $innerClassObject->render();
Then I display the contents of the OuterClass. The problem is that the rendered HTML of the inner class disappears and I see ">"; and "<" instead of actual tags. It seems that myVar is fully escaped prior to displaying its contents.
Since this approach doesn't work, what is the best way to nest PHPTAL templates? I guess it is possible and it is just a lack of knowledge at my end, so any input is appreciated.
source to share
If you want to insert arbitrary markup into the template, use the keyword structure
:
<div tal:content="structure variable_that_contains_html"/>
but if you want to embed one PHPTAL template within another use the macro:
macros.xhtml:
<div metal:define-macro="greeting">Hello World!</div>
page.xhtml:
<body><tal:block metal:use-macro="macros.xhtml/greeting"/></body>
source to share