Play with content and parts
Display content and parts
The default part content is the body part, so if you need to display the body, put this code at the appropriate place in your layout:
<?php echo $this->content(); ?>
Other content parts can be created by clicking the green “+” icon above the upper-right corner of the page editing box. (The red “-” icon deletes the active part/tab, so be careful!) If you need to display one of these “custom” parts, just add it to the parameter:
<?php echo $this->content('extended'); ?>
Note: if you write <?php echo $this->content(); ?> in a page content, you will get an infinite loop, and let me tell you that you don’t want an infinite loop, so don’t do it! ;) (In other words, only use that code in a layout, not a page.)
If you want the “part” to be inherited by “child” pages (and “grandchildren” pages, etc.) use the true parameter:
<?php $this->content('sidebar', true); ?>
Note: if the current page has its own equivalent “sidebar” part, then that will prevent the “inheritance” from the parent page from taking place.
Determine whether page content exists or not
By testing it before calling the method content(), just like this:
<?php echo $this->hasContent('sidebar') ? $this->content('sidebar'): ''; ?>
the other way is with an if condition like this:
<?php if ($this->hasContent('sidebar')): ?>
<div id="sidebar">
<?php echo $this->content('sidebar'); ?>
</div>
<?php endif; ?>
Don’t forget to close the if condition with endif;
