How I use a Company Details Page in Perch

by Will Moody

How I use a Company Details Page in Perch

It's important to make any CMS as easy to use for clients as possible, if it's hard to use you will get asked to help or explain multiple times how to do a simple task.

With Perch CMS I usually create a Company Details page, this is one page that has fields for the company name, address and phone number etc, which is then propagated and used throughout the website, simple to find and change if necessary for the client and means that it's simple to change say the company phone number from one place, which in turns reflects in every instance throughout the website..

This is the process and code I used:-

Process

Create a company_details.php page similar to the one below and save it, this creates a page which you will need to visit in your browser which in turn will show up any regions in your Perch control panel.

company_details.php

<!?php include('perch/runtime.php');

$contactDetails = perch_content_custom('Company Details', array(
'skip-template'=> true,
'page' => '/company_details.php'
));

perch_layout('head');

perch_layout('header');

perch_layout('nav'); ?>

<main id="content" class="content" role="main" tabindex="-1"><!-- main -->
   <div>
        <!?php perch_content('Company Details'); ?>
   </div>
</main><!-- main -->

<!?php perch_layout('footer'); ?>

This page firstly calls the Perch runtime, then has a section of code which creates a perch content region, this is followed by the pages various sections created by perch_layout components.

At the same time create a company-details.html file, similar to the one below and save it in your perch/templates/content folder.

company-details.html

<perch:content id="company_name" type="text" label="Company Name" required="" title="">
<perch:content id="address_line_1" type="text" label="Address Line 1" required="" divider-before="Company Address">
<perch:if exists="address_line_2"><perch:content id="address_line_2" type="text" label="Address Line 2"></perch:content></perch:if>
<perch:content id="village" type="text" label="Village" required="">
<perch:content id="city" type="text" label="Town/City" required="">
<perch:content id="county" type="text" label="County" required="">
<perch:content id="postcode" type="text" label="Postcode" required="">
<perch:content id="spaceless_phone" type="text" label="Phone Number with No Spaces" help="Enter as one long number with no spaces between area code and number, ie. 01603717078" divider-before="Company Phone Numbers">
<perch:content id="phone" type="text" label="Phone Number with Space" help="Enter as one long number with a single space between area code and number, ie. 01603 717078">
<perch:content id="spaceless_second_phone" type="text" label="Second Phone Number with No Spaces" help="Enter as one long number with no spaces between area code and number, ie. 01603717079">
<perch:content id="second_phone" type="text" label="Second Phone Number with Space" help="Enter as one long number with a single space between area code and number, ie. 01603 717079">
<perch:content id="spaceless_fax" type="text" label="Fax Number with No Spaces" help="Enter as one long number with a no spaces between area code and number, ie. 01603717066">
<perch:content id="fax" type="text" label="Fax Number with Space" help="Enter as one long number with a single space between area code and number, ie. 01603 717066">
<perch:content id="mobile" type="text" label="Mobile Number without Space" help="Enter as one long number with no spaces, should be eleven digits long">
<perch:content id="emailFirst" type="text" label="Your Email Address before the @ symbol" help="Dont include the @ symbol" required="" title="" divider-before="Company Email Address">
<perch:content id="emailLast" type="text" label="Your Email Address after the @ symbol" help="Dont include the @ symbol or finish with a full stop" required="" title="">

The company_details page will show up in your control panel page listing and under it will be in my case a 'Company Details' region, click on the region and fill in the relevant details, not forgetting to save when finished.

Then add this code snippet to each page, somewhere near the start, which calls in the company_details

<!?php
$contactDetails = perch_content_custom('Company Details', array(
'skip-template'=> true,
'page' => '/company_details.php'
));
?>

The last two lines of the company-details.html above, relate to how I use email addresses on websites, I use this code below in the head of each page. 

extract of head

<script>
 var first = "<?php echo $contactDetails[0]['emailFirst']; ?>";
 var last = "<?php echo $contactDetails[0]['emailLast']; ?>";
</script>

and this code whenever I want to display the email address. This is a simple method of displaying the email address while reducing the possibility for spam-bots to harvest it.

<script>document.write('<a href="mailto:' + first + '@' + last + '">' + first + '@' + last + '<\/a>');</script>

This is the method used throughout any pages of the website, say in the copyright section where you want to add the company name just after the copyright date, you would simply use something like this code, which displays the word 'Copyright' then the copyright symbol followed by the year date and finally the value entered as the company name in company-details.html via the control panel.

<p>Copyright
      <svg class="icon"><use xlink:href="../../assets/svg/regular.svg#copyright"></use></svg>
       <script>
        document.write(new Date().getFullYear())
      </script>
      <!?php echo $contactDetails[0]['company_name']; ?>
</p>

This method could easily be expanded to include other details as necessary, but the process would remain the same.