Forum

Thread tagged as: Question, Problem, Runway

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

Fishtank Creative

Fishtank Creative 2 points

  • 7 years ago

It works as I want it if I put ?s= in front of the slug

<a href="?s=<perch:content id="slug" type="slug" for="name" />">View</a>

But as you can imagine I would like the URL to be cleaner. Is there a way to change this so its / instead of ?=

Drew McLellan

Drew McLellan 2638 points
Perch Support

Set it from the page.

PerchSystem::set_var('path', '/teams/u16');

Then

<a href="<perch:content id="path" />/<perch:content id="slug" type="slug" for="name" />">View</a>

Would that then mean creating loads of master pages in order to change

PerchSystem::set_var('path', '/teams/u16');

for each page?

Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

Page Tree in Perch

But it doesn't if I add ?s= I just need to replace ?s= with / and not

Look at these screenshots of what happens.

URL for List Page (When I click on one of the links look what happens) URL List Page

URL for Detail Page (It gets rid of the subpage for some reason) Wrong URL for Detail page

Drew McLellan

Drew McLellan 2638 points
Perch Support

So could you do this?

 PerchSystem::set_var('path', PerchSystem::get_page());

Perfect!!!