dwoo-project / dwoo

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

Sub-templates cannot access data #59

Closed creativecat closed 6 years ago

creativecat commented 7 years ago

I'm trying to define a sub template with {template sub data}{/template} Using this I got a fatal error because of data is set to protected Fatal error: Uncaught Error: Cannot access protected property CAT_Helper_Template_DwooDriver::$data in /[...]/templates/backstrap/templates/default/backend_nav_sidebar.tpl.d132.php:26

I'm using a child class, that extends Dwoo\Core to handle templates. Everything works fine with 1.1.0 as $data was set public. Is there a reason why this had been changed in current version?

emulienfou commented 7 years ago

Hi! $data is now protected and can be accessed by the getData() method from Core class. This is just some changes made to have better code with setter and getter to interact with each properties.

creativecat commented 7 years ago

Mh... So the problem must be in the method for sub templates... I gonna take a look on it, maybe I find a solution to add a pull request!

creativecat commented 7 years ago

Do you know where the method for sub templates is implemented? I couldn't find it yet... I search for something like {template [name] [data]}, but with no success...

emulienfou commented 7 years ago

Can you send me your custom class and the template having problem. I'll try to reproduce your problem!

For now I do some tests and everything is working fine for me

webbird commented 6 years ago

The (sub) template uses $_root to access a "global" variable. That call is causing the error message.

webbird commented 6 years ago

I was able to fix this in Compiler.php method parseVarKey (line 2721ff):

                } elseif ($i === '_root' || $i === '__') {
// ---> old line                        #$output = '$this->data';
// ---> new line                        $output = '$this->getData()';
                    array_shift($m[2]);
                    array_shift($m[1]);
emulienfou commented 6 years ago

Hi @webbird thanks for that, can you do a PR, I don't work on this project anymore but will accept Pull-Request !

webbird commented 6 years ago

Of course. :)