Forum

Thread tagged as: Question, Configuration, Docs

General Settings (telephone, email, address)

Is there a good way to have sitewide config that can be re-used, for example a phone number and address can be rendered in many places, and so a single variable would be great to handle this, and edit via the UI.

At a look, the 'general settings' make sense to house this, but I wonder if there is somewhere else this sits.

Dan

Dan Duke

Dan Duke 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

yes that does sound like it. is there another approach to reduce duplication you would recommend, such as hardcode a static variable somewhere? otherwise, duplication of strings it is for now.

thanks, Dan

Simon Clay

Simon Clay 127 points

I often create a region called 'Company Details' and have fields in it for: Company Name, Address, Telephone, Email. I set it to 'share across all pages' (this places it in a nice position at the top of the Page UI). Then I use Perch Content Custom to output any of those details wherever needed in the site.

Simon that is a nice solution I hadn't thought of before

Simon, How are you rendering an individual variable in this way? At the moment, I am having to put a new content template for each variable, but imagine there is a much better way. I have the shared variables working nicely though, so thankyou for that

Simon Clay

Simon Clay 127 points

Hi Dan,

That's great. I use skip-template to avoid having to create different templates for each, like this:

<!-- First create the variables on the page (I usually do this somewhere near the top).  -->

<?php 
$contactDetails = perch_content_custom('Contact Details', array(
'skip-template'=>true,
'page' => '/contact/index.php'
));
?>

<!-- Then you can use any of the IDs to output anywhere on the page, like this -->

<p>Call us now on: <?php echo $contactDetails[0]['telephone']; ?></p>

Thanks Simon, that is a perfectly neat little solution, I will replace the excessive html files I have now and replace with what you shared.

Thanks for the help, Dan

Simon Clay

Simon Clay 127 points

\o/ that's great Dan, thanks.