Forum
List / Detail Generic Template
Ok this will difficult to explain, but here it goes.
On my website I will have a few pages that will use a default list/detail template called Team List / Team Detail
I created the pages and set the master page with the list / detail code
<?php
if (perch_get('s')) {
// Detail mode
perch_content_custom('Team', array(
'template' => 'squad/team_detail.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
} else {
// List mode
perch_content_custom('Team', array(
'template' => 'squad/team_list.html'
));
}
?>
This all works but the URLs are wrong. For example One page is called 'First Team' with the URL /teams/frist-team/
The Listing page works but when I click to the detail page the URL is /teams/slug But I want it to be /teams/first-team/slug
So I changed the URL pattern to /teams/first-team/[slug:s] And the detail page now works but in the template I would have to add the path in
<li>
<perch:content id="name" type="text" required="true" label="Full Name" title="true" />
<perch:content id="profile_image" type="image" label="Profile Image" bucket="squad-profile-images" />
<perch:content id="number" type="text" required="true" label="Number" />
<a href="first-team/<perch:content id="slug" type="slug" for="name" />">View</a>
</li>
But then this template doesn't become generic because I have to add first-team
in the a tag
Is there a way to keep this template generic so I can use this template again for other pages for example
/teams/u18s /teams/u16s
I don't want to create a list template for each team just so I can edit the URL path
Any help on this would be great.
Barry
It works as I want it if I put ?s= in front of the slug
But as you can imagine I would like the URL to be cleaner. Is there a way to change this so its / instead of ?=
Set it from the page.
Then
Would that then mean creating loads of master pages in order to change
for each page?
Ok - where can that value be found to set it dynamically? Is it on the URL? Or in some content?
Its on the url based on the pages I created in the Perch admin.
See the screenshot attached they each have their own page but when I click on the detail page it gets rid of the subpage from the url.
But it doesn't if I add
?s=
I just need to replace?s=
with/
and notLook at these screenshots of what happens.
URL for List Page (When I click on one of the links look what happens)
URL for Detail Page (It gets rid of the subpage for some reason)
So could you do this?
Perfect!!!