dwoo-project / dwoo

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

Support including a template that is inherited from a relative parent #83

Closed hoffmanns closed 6 years ago

hoffmanns commented 6 years ago

Currently, if a template includes template via an absolute path that is inherited, and the parent of the inherited template is linked relatively e.g. {extends "../root.html"}, an exception is thrown:

Dwoo\Compilation\Exception: Compilation error at line 1 in "file:tests/resources/include_extended/extended/extended.html" : Extends : When using an include path you can not reference a template into a parent directory (using ../) Example:

including.html:

<html>
{include "some/path/extended/extended.html"}
</html>

some/path/extended/extended.html:

{extends "../root.html"}
{block "content"}Extended{/block}

some/path/root.html:

<div>{block "content"}Root{/block}</div>

This constellation leads to calling Dwoo\Template\File::setIncludePath($paths) with a null argument and results in the includePath attribute holding an array with a single null element [0=>null] instead of an empty array, which this PR proposes.

This is affects Dwoo\Template\File::templateFactory:

if ($includePath = $parentTemplate->getIncludePath()) {

and throws the mentioned exception.

I have also included a test case for this constellation.

emulienfou commented 6 years ago

Thank you for this fix!