{init_sections}

Sections are objects which form website's hierarchial structure. Function {init_sections} retrieves a list of sections from given level of hierarchy or under given parent object.

Usage

{init_sections [parameter = value ..]}

Returns

Array of objects stored in variable which is defined by parameter "name".

Parameters

Common parametersFormatSince version
name

Defines the variable which stores the list of section objects returned. Default value is "section".

string 
parent

ID of an object who's child items are retrieved. Default value is the current object's ID which is usually the ID parameter in site URL. You can also define multiple ID-s by comma separating them.

comma separated integers 
buttons

Defines a list of actions displayed in v-shaped context menu. Default value is "new,edit,hide,move,delete". You can use any combination of those to restrict some of the actions by user.

comma separated string 
position

Position acts as a filter which allows you to group objects on web layout. Default value for sections is 0.

int 
on_create

By default, objects are set to be hidden/unpublished when created by user. You can force publishing by using on_create="publish". Default value is "hide". 

string4.0.2
Specific parameters to sections
  
levelLevel of the hierarchy to get sections from. When undefined, sub-sections of current level based on object ID in URL are displayed.int 
classes

In addition to sections, site hierachy can also contain hyperlink objects. Use classes="section, link" to retrieve these as well. Default value is "section".

comma separated string 
limit

This lets you limit the number of database rows to return.

int 
start

Results are retrieved starting from first row by default. You can set any other number to acheive paging for example. You must also define parameter "limit" when using "start". Default value is 0.

int 
order

Sort order of returned sections. This defines the order by clause in SQL sentence, you can use use any fields from tables obj, obj_obj and obj_section. Common usage: order="(title|date) (asc|desc)".

string3.3.2
Deprecated parameters
  
metadataDefines the metadata ID in Saurus CMS 3. In version 4, please use profiles instead of metadata.int 

Attributes

Common attributes      
id ID of the object. int  
parent_id ID of the parent object in site hierachy. int  
href Hyperlink address to the object in format of ?id=123. When aliases are used, returns alias name in public view instead. string  
title Title of the object. string  
buttons

Displays v-shaped context menu for authorized editors.

html  
class Class name of the object. Possible values are: "section, article, link, image, comment, poll, document, article's list, link list, login-box, subject, album, iframe-box, event" string  
comment_count Number of comments.  int 4.0.6
last_commented_time Time of last comment in format dd.mm.yyyy hh:ii. datetime 4.0.6
created_time Time of creation of the object in format of  dd.mm.yyyy hh:ii. datetime 4.0.3
fcreated_time Time of creation of the object in database default format, eg yyyy-mm-dd hh:ii.  datetime 4.0.3
created_user_id ID of the user who initially created the object.  int 4.0.3
created_user_name Name of the user who initially created the object.  string 4.0.3
changed_time

Time of last saving of the object in format dd.mm.yyyy hh:ii.

datetime 4.0.3
fchanged_time Time of last saving of the object in database default format, eg yyyy-mm-dd hh:ii. datetime 4.0.3
changed_user_id ID of the user who saved the object last. int 4.0.3
changed_user_name Name of the user who saved the object last. string 4.0.3
Specific attributes      
is_selected

Returns 1 when section belongs to the parent branch of current object. Useful for highlighting active menu items in templates.

boolean  

 General tags

<name>_newbutton Outputs action button for creating new object. html  
<name>_count Number of returned objects. When parameter "limit" is set, equals value of "limit". int  
<name>_counttotal Total number of objects found, not affected by "limit" parameter.  int 3.3.7

Examples

Display titles of each 1st level sections.

{init_sections name="section_list" level="1"}
{foreach from=$section_list item="section"}
    {$section->title}<br>
{/foreach}

Previous example with context menu buttons and linking titles. Also add button for creating new section if none exist.

{init_sections name="section_list" level="1"}
{foreach from=$section_list item="section"}
    {$section->buttons}<a href="{$section->href}">{$section->title}</a><br>
{foreachelse}
    {$section_list_newbutton}
{/foreach}

Display a bulleted list of 1st and 2nd level sections. Second level is only displayed under selected first level section.

{init_sections name="section_list_1" level="1"}
{if $section_list_1_count}
    <ul>
    {foreach from=$section_list_1 item="section_1"}
        <li>{$section_1->buttons}<a href="{$section_1->href}">{$section_1->title}</a>
        {if $section_1->is_selected}

            {init_sections name="section_list_2" parent=$section_1->id}
            {if $section_list_2_count}
                <ul>
                {foreach from=$section_list_2 item="section_2"}
                    <li>{$section_2->buttons}<a href="{$section_2->href}">{$section_2->title}</a></li>
                {/foreach}
                </ul>
            {else}
                <ul><li>{$section_list_2_newbutton}</li></ul>
            {/if}       
       
        {/if}
        </li>
    {/foreach}
    </ul>
{else}
    <ul><li>{$section_list_1_newbutton}</li></ul>
{/if}