How to customize the SimpleCatalog output

Erstellt am: Saturday 13 May 2017  |  Letzte Änderung am: Saturday 11 August 2018

Every time a page is loaded on your site, SimpleCatalog looks to determine whether it is assigned to this page and if that is the case, then outputs the associated content in place of the [[catalog_content]] variable that you have added to the page content with your page editor.

But what if you require more control over the entire output? - Sure, you could modify the frontend templates as written there: How to use SimpleCatalog templates.

But what will you do if you don't want to use the default URL structure like this one and just want to show a simple list of the items?

The SimpleCatalog gives you the $catalog API variable in your template. The $catalog variable can be used to customize the output. Furthermore, the complete ItemManager framework can be used, which includes all the methods for control over every aspect of SimpleCatalog data.

Let's just say, if you want to display the items of the category with id 25 within your index page, you can use $catalog->renderSection() method to parse certain areas manually. The next code example shows how you can proceed if you want to parse the FrontendItemList area manually:

if(get_page_slug(false) == 'index') {
    $catalog->renderSection('FrontendItemList', array('routeid' => 25));
    echo $catalog->content;

Simple Huh?

To show the pagination, use this code after the $catalog->renderSection() method is called:

echo $catalog->pagination;

The same is valid for the categories, to render the category list, do following ...


... and the next code row shows the rendered category list:

echo $catalog->content;

Here are some more areas you could output manually. Bread crumbs navigation:

echo $catalog->breadcrumbs;

Search results:

echo $catalog->content;

Search form:

echo $catalog->searchform;


Of course, you can also change all the variables on the fly that are used by SimpleCatalog for rendering of the several template sections. For example, to change the item list view, you could modify the itemRow template in this way:

$catalog->itemRow = '<div class="your-class"><h3>[[name]]</h3>...</div>';

Next, we are going to render the item list with modified template ...

$catalog->renderSection('FrontendItemList', array('routeid' => 25));

... and to output rendered content use:

echo $catalog->content;

Autor: Bigin  |  Tags:  FrameworkPHPGetSimpleDevelopmentItemManager