Jump to content

Open Lister detail in a different template


kaz
 Share

Recommended Posts

I have done news with Lister, the summary is output via foreach.
 

<?php foreach($pages->find('template=news, sort=date') as $item): ?>

I would like to open the full article via

<p><a href="<?= $item->url ?>">read more</a></p>

into another detail template (news-detail), which I have created.

Is there a way to open the $item content in a different detail template, perhaps a second 'template= … ?

Link to comment
Share on other sites

The most simple way to achieve that is to call a detail page (based on a detail template) and specify the news item with a get parameter like so:

<p><a href="/newsdetail/?newsid=<?= $item->id; ?>">read more</a></p>

In this case, your detail template would contain only the logic to receive an id and render the markup for $item with the given id. If you don’t like get parameters, you could alternatively use form submits instead of <a href> and send the ids as post variables.

  • Like 2
Link to comment
Share on other sites

A GET parameter is the way to go here, as @rash suggests.

You could also use the template name in the get parameter

<p><a href="<?= $item->url ?>?template=news-detail">read more</a></p>

and then in your news.php template do something like

if($input->get->template && $template = $input->get->text('template')) { // check for GET parameter 'template' and sanitize  
	$files->include("{$template}.php") // use $files API to include the template. All API variables (like $page) will be passed 
} else {
// your regular news.php template logic logic goes here
}

 

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