Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Sub-templates cannot access data #59

Closed
creativecat opened this issue Jan 21, 2017 · 8 comments
Closed

Sub-templates cannot access data #59

creativecat opened this issue Jan 21, 2017 · 8 comments
Assignees
Labels

Comments

@creativecat
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

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

@emulienfou emulienfou added the bug label Jan 24, 2017
@emulienfou emulienfou added this to the 1.3.4 milestone Jan 24, 2017
@emulienfou emulienfou self-assigned this Jan 24, 2017
@emulienfou emulienfou removed this from the 1.3.4 milestone Mar 7, 2017
@webbird
Copy link
Contributor

webbird commented Jan 30, 2018

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

@webbird
Copy link
Contributor

webbird commented Jan 30, 2018

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
Copy link
Contributor

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

@emulienfou emulienfou reopened this Jan 30, 2018
@webbird
Copy link
Contributor

webbird commented Jan 30, 2018

Of course. :)

emulienfou added a commit that referenced this issue Jan 30, 2018
emulienfou pushed a commit that referenced this issue Apr 18, 2018
(cherry picked from commit 97bb159)
@emulienfou emulienfou mentioned this issue Apr 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants