Jump to content

What page was the caller of render()?


thijs
 Share

Recommended Posts

Hey all,

Did I mention that ever since I started working with PW web development has gone /so/ much faster!

I’d like to ask you a question about the following; I’m building a so called ‘one-pager’, a website where all pages are on one single page. I’ve created the page structure in PW as I normally do, and I’m rendering all these pages as sections from one template which I’ve called home. I do want the individual sections to have their own url, and from these urls I’d like to render the home template. Nothing special so far, what I am after is the following: How can I figure out which page rendered the home template?

I remember seeing a topic about this, and the possibility of passing an options array to the render() method;

http://processwire.com/talk/topic/3145-multiple-views-for-templates/page-2?hl=%2Brender+%2Bcaller#entry32876

Is this functionality only available in the dev branch? Or is there another way of figuring out what page was originally requested? I’m running PW version 2.3.0.

Thanks in advance!

Thijs

Link to comment
Share on other sites

Hi thijs,

It's in the dev branch only. So you have two (there are more of course, it's Pw!) solutions:

  1. Use the dev version of Pw and get the page that rendered the template with $options['pageStack'].
  2. The method ryan mentioned in the post at the end. Before rendering the home template: $home->caller = $page; Then in your home template, you can access the caller page with $page->caller;
  • Like 3
Link to comment
Share on other sites

3. You can also adapt this method http://processwire.com/talk/topic/3551-small-tip-for-pages-that-will-be-used-with-render/

$path = str_replace ($config->urls->root,'/' , $_SERVER["REQUEST_URI"]); // so it works also when pw is in a subfolder
$caller = $pages->get($path)->title;

just to give more options ;)

  • Like 2
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...