pcreact Posted January 20, 2014 Share Posted January 20, 2014 Hello, I have a structure set up where I use "templates" like controllers and have my views in a separate /views/ directory. One of my template types is a "pageref-widget", it's basically just a widget that can be dropped anywhere in the site with a reference to a page to pull an overview from (title/intro description/image). In my pageref-widget controller I get a hold on the referenced page object and pass it to my partial view (using TemplateFile). I anticipated populating the view with the referenced page like this: $templateFile->set('page', $referencedPage); I realised when I did this that in the TemplateFile it's version of $page was not $referencedPage but the initial (global) $page object, I need to use $this->get('page') to access my referencedPage variable. It seems more logical to me that if $page has been explicitly passed to a template file that it should be accessible via $page (as all other explicity set non-global variables are), and that the global should need to be accessed via wire('{global}'), can anybody give me some insight into why it is the other way around? Thanks Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2014 Share Posted January 20, 2014 I'm not sure I can follow but want to mention an easy way current PW version has You could use .. echo $widgetpage->render(); .. In the widgetpage you then have a $options array with some things in it. $options["pagesStack"] // an array with the page from where the widgetpage is rendered. You can also use some options on render() echo $widgetpage->render("custom_template.php", array("somevar" => "a value")); Then your widget page is rendering with the custom_template.php and will also have the custom var $options["somevar"] 1 Link to comment Share on other sites More sharing options...
pcreact Posted January 21, 2014 Author Share Posted January 21, 2014 Thank for the reply Soma, $page->render("custom_template.php", array("somevar" => "a value")); That doesn't work for me, is this only available on a dev branch? Link to comment Share on other sites More sharing options...
Soma Posted January 21, 2014 Share Posted January 21, 2014 Yepsi dev, ths is what I assumed with "current". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now