Forum

Thread tagged as: Question

Controlling variables with perch:content?

Hi,

I'm working with the code from the Use Page Attributes for Open Graph Tags example, here's a snippet:

 $domain        = 'https://'.$_SERVER["HTTP_HOST"];
    $url           = $domain.$_SERVER["REQUEST_URI"];
    $sitename      = "The name of my website";
    $twittername   = "@mytwittername";
    $sharing_image = '/images/default_fb_image.jpg';

I'd like to be able to control the content of $sitename from within the Perch Admin. So instead of hardcoding the value The name of my website, I'd like to be able to change that in the CMS. How would I do that?

I've already got a global page, that contains the site name. I'm using perch_layout('global/global--site-name'); and <perch:layout path="global/global--site-name" /> to reuse that in different parts of the website.

Can I use that in $sitename?

Stephen Meehan

Stephen Meehan 4 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Most of the page functions take a final boolean argument which if set to true will return the result rather than echo it. You can use that to assign the result to a variable.

Great, adding this worked.

$sitename  = perch_layout('global/global--site-name', array(), true);

Thanks Drew!