Jump to content

merging in the globals to a TemplateFile - question


pcreact
 Share

Recommended Posts

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

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"] 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...