Forum
Best way to reuse content?
Hi
I have a page called Global Details, I use this to collect information I intend to use around the website, things like postal address, company number, social media URLs etc.
I was wondering, what's the recommended way to access this information to output in on the page?
Using perch content custom
?
<?php
perch_content_custom('Global Details', array(
'template' => '_global/address-line-2.html',
'page'=>'/global-details.php'
));
?>
Or using skip-template
with perch content custom
?
<?php
$html = perch_content_custom('Global Details', array(
'template' => '_global/address-line-2.html',
'page'=>'/global-details.php',
'skip-template' => true,
'return-html' => true,
));
echo $html['html'];
?>
I've created a demo page with config/debug turned on and tested each way. The Request time and Process time (is very fast) don't appear to be much different. The values change each time the page is refreshed.
Is there a preferred 'Perch way' of doing this?
Perch Runway: 3.0.10
Shared region. Then you can use anywhere with perch_content() or perch_content_custom().
Sorry, Runway:
Collection, but then perch_collection() with template and filter options.
There's no real difference between the two examples you gave. You'd do the latter if you wanted the
skip-template
output for some other purpose. Not sure why you'd do that if you didn't.Generally not a good idea to use a shared region for anything large.
Since this is Runway, he should just use a collection shouldn’t he? As collections are global and then using a template to output global in format required for that page...??
That would entirely depend on the content. If I have something that makes sense to exist as part of a page I'd have it as content. If was was just a collection of items to use around the site I'd use a Collection.
I definitely wouldn't use a Shared Region however. Those are only for simple bits of content such as your contact address that you want to display on several pages using the same template.
Hi all
Thanks for the replies.
It's good to know to stay away from shared regions for anything more complicated than a simple address etc.
I've created a 'Global details' page and I'm using
perch_content_custom
to pull out specific content as I need it.A
collection
doesn't feel like a good fit for this type particular type of content. Collections are great for templating repeating content, something like an address book or a catalogue of products. For this website there will only ever be one 'company name' or `phone number'.Thanks again - great support!
Hi Stephen,
I am trying to do something similar but just in the standard Perch, not Runway. I was hoping you could confirm something for me. I am assuming you don't actually every display your Global Details page? It is just used to store your global content values and then you use different templates to display the content in different areas of the website?
Also, would you mind maybe attaching a copy of your Global Details page so I can see how you have is structured?
Thanks
James
Hi James,
That's right
Yup.
Here's part of my global template, you can add other
perch
tags to collect any extra information.Say I wanted to use the ID
company_name
I'd just create a new HTML template (company-name.html), with just part of the global templateI'd then use this PHP to use that template.
Now when I update the company name in the Perch CMS the new name will be displayed on the page.
Does that help?
Hi Stephen
That is a fantastic answer - it helps heaps. Just one more question (I am fairly new to Perch). My understanding of Perch is that you need to visit the page in the browser first before the fields become available for editing in the Perch Dashboard. So, in the instance of your Global Details page, I presume you have a page called something like global-details.php which in turn is associated with the global-details.html template.
To have the template fields available in the Dashboard, did you have to visit the global-details page in your website? If so, how do you ensure visitors don't somehow stumble across this page in the future - I admit that would be extremely unlikely, but I wanted to check whether you had a strategy to serve up a 404 page or something similar. Or, is there another way to make the global-template fields accessible in the Dashboard without having to first visit the global details page in the browser?
Thanks heaps for your help.
James