In any Frontend Application the standard organization of contents in a section reflects the backend visualization. So, supposing to have a section named "section 1" structured like in figure 1, we'll have in frontend view the array $section
with different content types mixed together:
Array( ['id'] => section 1 ['nickname'] => section-1 ... ['childContents'] => Array( [0] => Array(...), [1] => Array(...) ... ) );
This is ok in many situation i.e. when I want to list contents in sequential order, but when I want contents to assume a specific behavior based on their semantic meaning this structure is limited.
In every object array I have a key named object_type that identify the type of the item (Document, Event, Gallery, etc...) so we can iterate the $childContents array and check that key to choose the right behavior. But this is not a good practice in some situations: for example if I want that in a 3 columns layout documents are shown in the first column, events in the second and galleries in the third column. Infact I should iterate the childContents array three times. Another example could be this one: we don't know which types of objects are in a section but we want everyone to behave differently.
In these cases the $sectionOptions
attribute of the FrontendController class helps us.
The first solution: semantic separation for all sections
In this first case we want in our frontend application the objects inside every section divided by type. To do this we will override the $sectionOptions
attribute in Pages Controller like this:
class PagesController extends FrontendController { protected $sectionOptions = array( "showAllContents" => true, "itemsByType" => true, "childrenParams" => array() ); ... }
setting itemsByType to true we force BEdita objects inside a section to be divided by object type. Instead of "chidContents" we'll have "children" array:
Array( ['id'] => 'section 1', ['nickname'] => 'section-1', ... ['children'] => Array( ['Document'] => Array( [0] => Array(...), [1] => Array(...) ) ['Event'] => Array(...) ... ) );
The second solution: semantic division only for that section
In this case we'll use the nicknameBeforeFilter callback called automatically before section data are loaded (note that "-" char in nickname is replaced with "_" in method name):
protected function section_1BeforeFilter() { $this->sectionOptions["itemsByType"] = true; }
The result will be an array like that above.