Forum

Thread tagged as: Question, Problem, Runway

How do you get Collection content into Page Title

I am currently using this code for the global header, however what needs to go in to get the 'make' field from my 'make' collection if I am on a Make page?

if (perch_layout_has('blog-post')) {
        perch_blog_post_meta(perch_get('s'));
    }
    elseif (perch_get('cat')) { echo '<title>';
    perch_blog_category(perch_get('cat'));
    echo ' Car Leasing Blog</title>';
    }
    elseif (perch_get('tag')) { echo '<title>Articles tagged with ';
    perch_blog_tag(perch_get('tag'));
    echo '</title>';
    }
    elseif (perch_get('make_slug')) { echo '<title>';


        ???????????

        echo ' Car Leasing</title>';
        }

    else{
        echo '<title>' . perch_pages_title(true) . '</title>';
        perch_page_attributes(array(
        'template' => 'seo.html'
        ));
    }

Neil Duddridge

Neil Duddridge 1 points

  • 4 years ago

I figured it out :)

    elseif (perch_get('make_slug')) { 

        perch_get(perch_collection('Make', [
        'filter' => 'slug',
        'template' => 'make_meta.html',
        'value'  => perch_get('make_slug'),
        ]));    

        }

If there is a better or cleaner way let me know! :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the purpose of the perch_get() around the perch_collection() ?

It didn't seem to work when I tried it initially, I'll try it again without :)

Ok stripped that out now, works fine still. I was scratching my head about it earlier as I kept getting a blank page.

Code now:

elseif (perch_get('make_slug')) { 

perch_collection('Make', [
'filter' => 'slug',
'template' => 'make_meta.html',
'value' => perch_get('make_slug'),
]); 

}