This guide explains how we can use the Composer of Concrete5 to create a fully working News system. Each news will be composed of the following elements: - Title - Publishing date - Short formatted preview text - Thumbnail - Main formatted news text By following this guide, it’s easy to extend this list to include even more elements.
The custom attributes are necessary for saving non-standard information such as the formatted preview text or the thumbnail.
The new page type is a template that serves as a model for future news. Each news will have its own page of this type that will be created from this model.
The “news list” is the page where we will display a list of all our news. Additionally, new news pages will be created as subpages of this page.
I followed the guide that I found here to be able to write news using the composer feature of concrete5. The composer allows for the creation of new pages of a certain type without leaving the backend (Dashboard) of concrete5.
What good are our newly created news if we can’t display them in a nice list with their thumbnail and the formatted news description? However, this is the most difficult part as you’ll have to create a new block template and even write/modify some PHP code.
The creation of the template PHP file is by far the most difficult step. However, you can have a look at the template files provided in
For the thumbnail to work, we have to extract the image from the custom attribute “news_thumbnail” that we created and display it in the list. The following PHP code will take care of that:
<?php
$newsThumbnailAttribute = $cobj->getAttribute('news_thumbnail');
if (is_object($newsThumbnailAttribute)) {
$imgHelper->outputThumbnail($newsThumbnailAttribute, 120, 120, $title);
}
?>
For the formatted short description to work, we have to extract the formatted text from the custom attribute “news_descriptionl” that we created and display it in the list. The following PHP code will take care of that:
<?php
$newsDescription = $cobj->getAttribute('news_description');
if (!empty($newsDescription)) {
echo $newsDescription;
}
?>