Noob question about Site Set Attributes (5.8)
Permalink
Hi all, I'm fairly new to the C5 arena so please go easy on me if this seems stupid.
I'm wanting to set a global attribute for a site (a url for an external booking link). I'd like the client to be able to edit this value if they see fit and it propagate throughout the theme so I thought I'd at a new Set with a custom attribute within the Site category (presuming thats the category for sitewide attributes?). Trying it this way rather than hardcoding it into the theme pages.
Question is how do I retrieve the values inside the Site Set within my theme? My custom attribute has a handle of 'booking_url' inside a set 'booking_details'.
I'm wanting to set a global attribute for a site (a url for an external booking link). I'd like the client to be able to edit this value if they see fit and it propagate throughout the theme so I thought I'd at a new Set with a custom attribute within the Site category (presuming thats the category for sitewide attributes?). Trying it this way rather than hardcoding it into the theme pages.
Question is how do I retrieve the values inside the Site Set within my theme? My custom attribute has a handle of 'booking_url' inside a set 'booking_details'.
You could simply use a sitewide (global) area and use either the content or html block within it. If your theme doesn't have a global area where you want it to be editable, you'll need to add one.
And just drop a content (or HTML) block in there with the link.
<?php $a = new GlobalArea('Booking Link'); $a->display($c); ?>
And just drop a content (or HTML) block in there with the link.
Thanks for the suggestions. Found a solution in the 8.0 release notes which says:
Custom attributes can now be globally applied to your site, and easily accessed by calling
I created my custom attribute in System & Settings > Basics, targeted the handle with the above code and all is well :)
Custom attributes can now be globally applied to your site, and easily accessed by calling
\Site::getSite()->getAttribute(‘attribute_handle’);
I created my custom attribute in System & Settings > Basics, targeted the handle with the above code and all is well :)
Thanks for sharing!
I'm using that in a page template:
Works in C5 version 8.5.2
I'm using that in a page template:
<?php echo Site::getSite()->getAttribute('attribute_handle'); ?>
Works in C5 version 8.5.2
Getting all attributes in a set:
http://www.webli.us/cheatsheet/doku.php#get_all_attributes_in_a_set...
Getting a specific attribute:
http://www.webli.us/cheatsheet/doku.php#get_an_attribute_key_by_han...