Forum

Thread tagged as: Question, Runway

Runway: Creating an entry page for collection items?

I'm trying to create an article page when clicked on from an archive of articles (collections).

Using the following will display all articles, but I only want to show the relevant article that is selected from the archive view.

<?php
     perch_collection('Knowledge Articles', [
     'template' => 'cpi/knowledge_article.html',
?>

It occurred to me that I should be using the slug to achieve this - I looked in the documentation to see how this is done elsewhere and found (how to create a detail page)[https://solutions.grabaperch.com/architecture/how-do-i-create-list-detail-pages] This however doesn't work but is there something similar that I should be doing?

<?php
perch_collection('Knowledge Articles', [
  'template' => 'cpi/knowledge_article.html',
  'filter'        => 'slug',
  'match'     => 'eq',
  value'       => perch_get('s'),
  'count'      =>1
]); 
?>
Dan Lee

Dan Lee 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Both look fine once you fix the syntax errors.

<?php
     perch_collection('Knowledge Articles', [
        'template' => 'cpi/knowledge_article.html',
    ]);
?>

and

<?php
perch_collection('Knowledge Articles', [
  'template' => 'cpi/knowledge_article.html',
  'filter'        => 'slug',
  'match'     => 'eq',
  'value'       => perch_get('s'),
  'count'      =>1
]); 
?>

It might be a good idea to turn PHP's error display on in your dev environment - it'll help you catch typos.

Dan Lee

Dan Lee 1 points

Looks like the syntax is ok in my code - it might have been me copying and pasting it wrong. I'm still having the same problem - nothing is showing on the article page once I add the filter, match and value settings to the function.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of s in your route?

Dan Lee

Dan Lee 1 points

So I'm assuming s stands for "slug" for the article? In essence I'm replicating the structure of the Blog App with Runway with it's post template and assigning it to a page. For the Article Page I'm doing the following with it's Route.

The Route: "knowledge-base/[slug:cat]/[slug:s]"

So the URL structure would be: knowledge-base/category-name/article-name

I'm capturing the slug for the articles using the following in it's template.

<perch:content id="titleSlug" type="slug" for="title" label="Slug" editable="true" order="2" suppress="true" />

You should be using the id of titleSlug on your filter

As that's the id that you're using in your template

Dan Lee

Dan Lee 1 points

Thanks Dexter!

That seemed to do the job.

I'm having the same problem like Dan and I just can't manage to work things out.

Basically, I have a home page that displays latest post with this code

    <?php
        perch_collection('Wallpapers', [
            'template'   => 'wallpaper.html',
            'sort'       => 'date',
            'sort-order' => 'DESC',
            'count'      => 1,
        ]);
    ?>

The data is captured via wallpaper.html template

    <div class="section-content w-clearfix">
        <div class="iphone">

            <img class="iphone-image" src="<perch:content id="iPhoneImageOne" type="image" label="iPhone" />" />

            <div class="iphone-wallpaper">
                <img src="<perch:content id="WallpaperImage" type="image" label="Add Wallpaper image" bucket="Wallpapers" width="220" height="391" />" alt="iPhone wallpaper - <perch:content id="WallpaperName" type="text" label="Alt text" order="2" />" />
                    <perch:content id="WallpaperImage" type="image" label="Add Wallpaper image" bucket="Wallpapers" width="1080" height="1920" suppress="true" />    
                    <perch:content id="WallpaperImage" type="image" label="Add Wallpaper image" bucket="Wallpapers" width="1080" height="900" crop="true" suppress="true" />
                    <perch:content id="WallpaperImage" type="image" label="Add Wallpaper image" bucket="Wallpapers" width="110" height="196" suppress="true" />
            </div>
        </div>

        <div class="description">
            <div class="caps text-small">Wallpaper name</div>
            <h1 class="heading-centered"><perch:content id="WallpaperName" type="text" label="Wallpaper name" required="true" title="true" order="1" /></h1>
            <a class="button-primary w-button" href="<perch:content id="WallpaperImage" type="file" label="Wallpaper image" bucket="Wallpapers" width="1080" height="1920" />">Download wallpaper</a>
            <div class="text-small">Image size: <perch:content id="WallpaperImage" type="image" output="size" format="MB" /> (<perch:content id="WallpaperImage" type="image" output="size" />)</div>
        </div>
    </div>

    <perch:content id="date" type="date" label="Date" format="%d %B %Y" required="true" suppress="true" />

    <perch:content id="mirko" type="slug" for="WallpaperName" label="Slug" editable="true" suppress="true" />

I have a list and detail page. Here is the code for the list page

        <?php
            perch_collection('Wallpapers', [
                'template'   => 'all_wallpapers.html',
                'sort'       => 'date',
                'sort-order' => 'DESC',
                'count'      => 10,
            ]);
        ?>

And this is the code that shows all wallpapers

        <div class="block-one-wallpaper">
        <div class="caps text-small"><perch:content id="WallpaperName" type="text" label="Wallpaper name" required="true" title="true" /></div>
        <div class="text-small">Image size: <perch:content id="WallpaperImage" type="image" output="size" format="MB" /> (<perch:content id="WallpaperImage" type="image" output="size" />)</div>

            <a class="w-inline-block wallpaper-in-list" data-ix="hover-wallpaper" href="/wallpapers/<perch:content id="mirko" type="slug" for="WallpaperName" />">
            <img src="<perch:content id="WallpaperImage" type="image" label="Add Wallpaper image" bucket="Wallpapers" width="220" height="391" />" alt="iPhone wallpaper - <perch:content id="WallpaperName" type="text" label="Alt text" />">
            </a>

        </div>

I just can’t manage to show one item selected from list to display on detail page.

Here is the detail page code

    <?php perch_collection('Wallpapers', [ 
        'template' => 'wallpaper.html', 
        'filter' => 'slug', 
        'match' => 'eq', 
        'value' => perch_get('mirko'), 
        'count' =>1 
        ]);  
    ?>

Also, the route URL pattern for this page is

wallpapers/[slug]

What am I doing wrong?

You're asking perch to get mirko but it doesn't know where from.

Your route needs to be wallpapers/[slug:mirko]

Updated but nothing is showing up...... :( Here is a debug message

SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch8_pages p LEFT JOIN perch8_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
Matched route: wallpapers/[slug:mirko]
Using master page: /templates/pages/one-wallpaper.php
Page arguments:
Array
(
    [0] => /wallpapers/first
    [mirko] => first
    [1] => first
)
[1] SELECT * FROM perch8_pages WHERE pagePath='/wallpapers/' LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
[3] SELECT regionKey, regionHTML FROM perch8_content_regions WHERE regionPage='/wallpapers/' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT collectionID, collectionTemplate FROM perch8_collections WHERE collectionKey='Wallpapers'
[nil] SELECT * FROM ( SELECT idx.itemID, ci.collectionID, ci.itemJSON, idx2.indexValue as sortval FROM perch8_collection_index idx JOIN perch8_collection_items ci ON idx.itemID=ci.itemID AND idx.itemRev=ci.itemRev AND idx.collectionID=ci.collectionID JOIN perch8_collection_revisions cr ON idx.itemID=cr.itemID AND idx.itemRev=cr.itemRev AND idx.collectionID=ci.collectionID JOIN perch8_collection_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE (idx.collectionID=1) AND ((idx.indexKey='slug' AND idx.indexValue='first')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1
Using template: /templates/content/wallpaper.html
[17] SELECT DISTINCT settingID, settingValue FROM perch8_settings WHERE userID=0
Request time: 0.1926
Process time: 0.1894
Memory: 3.2755

Ahh plus, you're filtering on an id called slug of which doesn't exist. It's got the ID of mirko.

You need to change filter from slug to mirko

Ok, I should write it like this?

    <?php perch_collection('Wallpapers', [ 
        'template' => 'wallpaper.html', 
        'filter' => 'mirko', 
        'match' => 'eq', 
        'value' => perch_get('wallpapers/[slug:mirko]'), 
        'count' =>1 
        ]);  
    ?>

Sorry no,

Are you on perch or perch runway?

<?php 
perch_collection('Wallpapers', [
    'template' => 'wallpaper.html',
    'filter' => 'mirko',
    'match' => 'eq',
    'value' => perch_get('mirko'), 
    'count' =>1  
]);  
?>

SOLVED!!!! It works!!!!!! :D Thanks Dexter!!!!!!!!!!!

    <?php perch_collection('Wallpapers', [ 
        'template' => 'wallpaper.html', 
        'filter' => 'mirko', 
        'match' => 'eq', 
        'value' => perch_get('mirko'), 
        'count' =>1 
        ]);  
    ?>

Runway!