Setting up and customising concrete5's Composer
The Composer is one of our favourite features of concrete5 - in this video we outline how to set it up for a custom page type and how to output custom page attributes on page templates and block templates.
Covered in the video, but for reference:
Steps to create a new page type and enable it for use in the composer
The video and these steps assumes you are developing a site with your own template.
- Turn off caching
- Identify the name of the new page you want to create, duplicate an existing page type in your theme and rename it to the name of the new page type, with a .php extension.
- Visit the Themes section in the Dashboard, inspect the theme and create the new page type.
- In the Page Attributes section of the Dashboard, create custom page attributes that effectively match the fields of data you wish to store (e.g. size, shape, colour, price, image).
- Visit Page Types in the Dashboard, press the Composer button for your new page type. Enable the page for the composer and check the attributes you would like on your composer form.
- (Optional) - via Page Types, you can visit the 'Default' for the new page, add empty blocks to the page, click on them and select 'Composer Settings' to name and enable them for use in the composer form.
To make page attributes and other data display on your custom page type
Edit the file you created for your custom page type and add some of the following:
// output the name of the page
echo $c->getCollectionName();
// output the page's description
echo $c->getCollectionDescription();
// output the date for the page
echo $c->getCollectionDatePublic();
// output an attribute (something simple like a text attribute)
echo $c->getAttribute('name_of_attribute');
In the case of outputting an image, you would use the following code:
<?php
// load up the image helper at the top of your page template
$ih = Loader::helper('image');
// fetch a file/image attribute and store in image
$img = $c->getAttribute('image_handle');
?>
<?php
if ($img) { // test if the image actually exists before resizing and outputting
$thumb = $ih->getThumbnail($img, 200, 999, false); // change false to true to crop image
?>
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<?php } ?>
The same outputting functions apply if you are editing a custom template for a page list block, except the variable $c is going to be $page in the loop through the pages. Make sure you review the commented out code in the default view.php file for the page list block for examples on how to output page attributes.
-Ryan