dwoo-project / dwoo

[UNMAINTAINED] php template engine
http://dwoo.org
GNU Lesser General Public License v3.0
167 stars 58 forks source link

Include files from string template #81

Open zodinyac opened 6 years ago

zodinyac commented 6 years ago

The following code doesn't work:

$str   = new Dwoo\Template\Str('{include(file="test.tpl")}');
echo $tpl->get($str);

$str is Str object and doesn't have correct templateFactory.

When I do

$str   = new Dwoo\Template\Str('{include(file="file:test.tpl")}');
echo $tpl->get($str);

It works when I added to File::templateFactory the following code:

if ($parentTemplate === null) {
    $parentTemplate = $core->getTemplate();
}
if (!($parentTemplate instanceof self)) { // added
    $includePath = $core->getTemplateDir(); // added
} // added
if ($parentTemplate instanceof self) {

And removed:

$class = 'Dwoo\Template\File';
if ($parentTemplate) {
    $class = get_class($parentTemplate); // removed this line
}

How I can fix this correctly? I can not use file templates from string templates.