Jump to content

Render other Page depending on URL Segments


ov3rtak3r
 Share

Recommended Posts

Hello everyone!

I am new to Processwire and really like it, but now I have a problem that I can't solve by myself.

I have created following templates:

data_people (no template-file)
person_listing (person_listing.php)
person_detail (person_detail.php)

I have added the following Pages:

Actor, Director, Stuff using template person_listing.php [visible in frontend]
"People" using template data_people [not visible, only for data]
-> "Georg Klonee" using template person_detail [is visible, but should not be shown using path /en/person/georg-klonee]

Example Person: Georg Klonee

The Problem:

He is a Actor and a Director, so I want him to be shown in the Listing of /en/actors and /en/directors. No problem until here - it works. But now, when I click him, the URL for the Detail-Page is unfortunately /en/person/georg-klonee. But I want it to be /en/actors/georg-klonee, if i open the details from Actors-Page (and of course /en/directors/georg-klonee when on Directors-Page).

How can I get this to work? I am also using TemplateEngine-Module with TemplateTwigEngine-Module, hopefully this won't be a problem? I tried it with URL-Segments for person_listing.php. But how can I abort the rendering of people_listing and start rendering person_detail.php?

 

Thanks for your help in advance. :)

Link to comment
Share on other sites

I found a way to solve my problem, the Post helped me too:

Quote

 

The code looks the following and works with the TemplateEngineModule. If you want my solution to work without the TemplateEngineModule, remove the line $view->setFilename('person');.

Template person_listing Settings in Backend:

The allowed Page URL Segments:

regex:^[0-9a-zA-Z\-\_]+$

Template person_listing.php Code:

if ($input->urlSegment1) {
  
  $pagename = $input->urlSegment1;
  $match = $pages->get('name='.$pagename);
  if (!$match->id) throw new Wire404Exception();
  $view->setFilename('person'); // Remove this line if you don't use TemplateEngineModule!
  echo $match->render();
	
  return $this->halt();
}

Hope this helps someone else.

  • Like 3
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

×
×
  • Create New...