Jump to content
Boost up your community
  • Create Templates

    Now it is time to create templates for the database. In your AdminCP go to Pages -> Page management -> Templates. Click on New and select Add Database Template. Enter Docs in the Name field and select Record listing in Template Type. Assign the template to our database Documentation.

    create-new-database-template.png

    A new template set Docs will be created. It contains several template bits for the listing of the records.

    Let's add another set of template bits to it. It will handle displaying the records in the database. Execute exactly the same steps as in the previous step (see screenshot above), except that you choose Record in Template Type. When you save it, you will have a template set called Docs on the left side, which contains all the required template bits.

    Template set for database

    Below you will find the code for each template bit.

    Display record - Template bit record

    This template controls the display of single guide page so called main content. Before you replace the code of this template, you can look at a single guide in documentation and see how it is visually structured. Then replace the content of the template with the code below and look at the page again. This is the best way to see what has changed.

    Spoiler
    
    {{if $record::database()->can('add') or \IPS\Member::loggedIn()->member_id}}
    <ul class="ipsToolList ipsToolList_horizontal ipsClearfix ipsSpacer_both ipsResponsive_hidePhone">
        {{if $record::database()->can('add')}}
        {{$page = \IPS\cms\Pages\Page::$currentPage;}}
        <li class='ipsToolList_primaryAction'>
            <a class="ipsButton ipsButton_medium ipsButton_important ipsButton_fullWidth" data-ipsDialog="1" data-ipsDialog-size="narrow" data-ipsDialog-title="{lang="cms_select_category"}" href="{$page->url()->setQueryString( array( 'do' => 'form', 'd' =>
            \IPS\cms\Databases\Dispatcher::i()->databaseId ) )}">{lang="cms_add_new_record_button" sprintf="$record::database()->recordWord( 1 )"}</a>
        </li>
        {{endif}}
    </ul>
    {{endif}}
    
    <div class='ipsClearfix'>
        <h1 class='ipsType_pageTitle ipsType_break'>
            {{if $record->locked()}}<span><i class='fa fa-lock'></i></span> {{endif}}
    
            {{if $record->isFutureDate() || $record->mapped('pinned') || $record->mapped('featured') || $record->hidden() === -1 || $record->hidden() === 1}}
            {{if $record->isFutureDate()}}
            <span><span class="ipsBadge ipsBadge_icon ipsBadge_warning" data-ipsTooltip title='{$record->futureDateBlurb()}'><i class='fa fa-clock-o'></i></span></span>
            {{elseif $record->hidden() === -1}}
            <span><span class="ipsBadge ipsBadge_icon ipsBadge_warning" data-ipsTooltip title='{$record->hiddenBlurb()}'><i class='fa fa-eye-slash'></i></span></span>
            {{elseif $record->hidden() === 1}}
            <span><span class="ipsBadge ipsBadge_icon ipsBadge_warning" data-ipsTooltip title='{lang="pending_approval"}'><i class='fa fa-warning'></i></span></span>
            {{endif}}
            {{if $record->mapped('pinned')}}
            <span><span class="ipsBadge ipsBadge_icon ipsBadge_positive" data-ipsTooltip title='{lang="pinned"}'><i class='fa fa-thumb-tack'></i></span></span>
            {{endif}}
            {{if $record->mapped('featured')}}
            <span><span class="ipsBadge ipsBadge_icon ipsBadge_positive" data-ipsTooltip title='{lang="featured"}'><i class='fa fa-star'></i></span></span>
            {{endif}}
            {{endif}}
    
            {{if $record->prefix() OR ( $record->canEdit() AND $record::canTag( NULL, $record->container() ) AND $record::canPrefix( NULL, $record->container() ) )}}
            <span {{if !$record->prefix()}}class='ipsHide'{{endif}} {{if ( $record->canEdit() AND $record::canTag( NULL, $record->container() ) AND $record::canPrefix( NULL, $record->container() ) )}}data-editablePrefix{{endif}}>
    				{template="prefix" group="global" app="core" params="$record->prefix( TRUE ), $record->prefix()"}
    			</span>
            {{endif}}
            {{if $record->canEdit()}}
            <div class='ipsType_break ipsContained' data-controller="core.front.core.moderation">
                <span data-role="editableTitle" title='{lang="click_hold_edit"}'>{$record->_title}</span>
            </div>
            {{else}}
            <div class='ipsType_break ipsContained'>{$record->_title}</div>
            {{endif}}
        </h1>
    
    </div>
    
    {{if count( $record->tags() ) OR ( $record->canEdit() AND $record::canTag( NULL, $record->container() ) )}}
    {template="tags" group="global" app="core" params="$record->tags(), FALSE, FALSE, ( $record->canEdit() AND $record::canTag( NULL, $record->container() ) ) ? $record->url() : NULL"}
    {{endif}}
    
    <article class='ipsContained ipsSpacer_top'>
        <div class='ipsClearfix'>
            <section class="ipsType_richText ipsType_normal" data-controller='core.front.core.lightboxedImages,guides.menu'>{$record->_content|raw}</section>
    
            {{if $record->editLine()}}
            {$record->editLine()|raw}
            {{endif}}
    
            {{if $records = $record->getReciprocalItems()}}
            {{$infoLineShown = FALSE;}}
            <br>
            {{foreach $records as $fieldId => $items}}
            <ul class="ipsList_inline ipsList_csv ipsList_noSpacing">
                {{foreach $items as $item}}
                <li>{{if ! $infoLineShown}}{{$infoLineShown=TRUE;}}{lang="records_linking_to_me" sprintf="$item::database()->recordWord(0,TRUE), $record::database()->recordWord(1)"}: {{endif}}<a href="{$item->url()}">{$item->_title}</a></li>
                {{endforeach}}
            </ul>
            {{endforeach}}
            {{endif}}
        </div>
        {{if $bottomFields = $record->customFieldsForDisplay('display_bottom')}}
        <hr class='ipsHr ipsClear ipsClearfix'>
        {{foreach $bottomFields as $fieldId => $fieldValue}}
        {{if $fieldValue}}
        {$fieldValue|raw}
        {{endif}}
        {{endforeach}}
        {{endif}}
        {{if $record instanceof \IPS\Content\Reputation and settings.reputation_enabled}}
        <div class='ipsPos_right'>
            {template="reputation" app="core" group="global" params="$record"}
            <br>
        </div>
        {{endif}}
        <hr class='ipsHr ipsClear ipsClearfix'>
        {{if $record->isFutureDate() or $record->canPin() or $record->canUnpin() or $record->canFeature() or $record->canUnfeature() or $record->canHide() or $record->canUnhide() or $record->canMove() or $record->canLock() or $record->canUnlock() or $record->canDelete()}}
        <a href='#elentryActions_menu' id='elentryActions' class='ipsButton ipsButton_light ipsButton_verySmall' data-ipsMenu>{lang="content_record_actions" sprintf="$record::database()->recordWord( 1, TRUE )"} <i class='fa fa-caret-down'></i></a>
        <ul id='elentryActions_menu' class='ipsMenu ipsMenu_auto ipsHide'>
            {{if $record->isFutureDate() and $record::canFuturePublish( NULL, $record->container() )}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'publish' ) )}' data-confirm title='{lang="publish_now"}'>{lang="publish"}</a></li>
            {{endif}}
            {{if $record->canFeature()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'feature' ) )}' title='{lang="feature_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="feature"}</a></li>
            {{endif}}
            {{if $record->canUnfeature()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'unfeature' ) )}' title='{lang="unfeature_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="unfeature"}</a></li>
            {{endif}}
            {{if $record->canPin()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'pin' ) )}' title='{lang="pin_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="pin"}</a></li>
            {{endif}}
            {{if $record->canUnpin()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'unpin' ) )}' title='{lang="unpin_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="unpin"}</a></li>
            {{endif}}
            {{if $record->canHide()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'hide' ) )}' title='{lang="hide_title_record" sprintf="$record::database()->recordWord(1)"}' data-ipsDialog data-ipsDialog-title="{lang="hide"}">{lang="hide"}</a></li>
            {{endif}}
            {{if $record->canUnhide()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'unhide' ) )}' title='{{if $record->hidden() === 1}}{lang="approve_title_record" sprintf="$record::database()->recordWord(1)"}{{else}}{lang="unhide_title_record" sprintf="$record::database()->recordWord(1)"}{{endif}}'>{{if $record->hidden() === 1}}{lang="approve"}{{else}}{lang="unhide"}{{endif}}</a></li>
            {{endif}}
            {{if $record->canLock()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'lock' ) )}' title='{lang="lock_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="lock"}</a></li>
            {{endif}}
            {{if $record->canUnlock()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'unlock' ) )}' title='{lang="unlock_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="unlock"}</a></li>
            {{endif}}
            {{if $record->canMove()}}
            <li class='ipsMenu_item'><a href='{$record->url('move')->csrf()}' data-ipsDialog data-ipsDialog-title="{lang="move"}"  title='{lang="move_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="move"}</a></li>
            {{endif}}
            {{if $record->canDelete()}}
            <li class='ipsMenu_item'><a href='{$record->url('moderate')->csrf()->setQueryString( array( 'action' => 'delete' ) )}' data-confirm  title='{lang="delete_title_record" sprintf="$record::database()->recordWord(1)"}'>{lang="delete"}</a></li>
            {{endif}}
            {{if \IPS\Member::loggedIn()->modPermission('can_view_moderation_log')}}
            <li class='ipsMenu_sep'><hr></li>
            <li class="ipsMenu_item"><a href='{$record->url()->csrf()->setQueryString( array( 'do' => 'modLog' ) )}' data-ipsDialog data-ipsDialog-title='{lang="moderation_history"}'>{lang="moderation_history"}</a></li>
            {{endif}}
        </ul>
        {{endif}}
        {{if $record->canEdit()}}
        &nbsp;&nbsp;<a href='{$record->url('edit')->csrf()}' title='{lang="edit"}'>{lang="edit"}</a>
        {{endif}}
        {{if !\IPS\Member::loggedIn()->group['gbw_no_report'] }}
        &nbsp;&nbsp;<a href='{$record->url('report')}' data-ipsDialog data-ipsDialog-size='medium' data-ipsDialog-title="{lang="content_record_report" sprintf="$record::database()->recordWord( 1, TRUE )"}" data-ipsDialog-remoteSubmit data-ipsDialog-flashMessage="{lang="report_submit_success"}" title="{lang="content_record_report" sprintf="$record::database()->recordWord( 1, TRUE )"}">{lang="content_record_report" sprintf="$record::database()->recordWord( 1, TRUE )"}</a>
        {{endif}}
        {{if $record->canManageRevisions()}}
        &nbsp;&nbsp;<a href='{$record->url('revisions')}' title="{lang="content_view_revisions"}">{lang="content_view_revisions"}</a>
        {{endif}}
    </article>
    
    <br>
    {{if $updateForm}}
    <div class='ipsAreaBackground_light ipsPad'>
        <h2 class='ipsType_sectionHead'>{lang="cms_front_update_fields" sprintf="$record::database()->recordWord( 1 )"}</h2>
        <ul class='ipsForm ipsForm_vertical'>
            {$updateForm|raw}
        </ul>
    </div>
    {{endif}}

     

    Some features such as rating have been removed from the template as they are not needed in the documentation. This way template looks cleaner and readable. Another approach is to leave everything inside when you create your own templates, even what is not used at the moment, but possibly later.

    Categories - Templates categoryHeader, categoryFooter and categoryTable

    These three templates control the list of records in a category. In my example it would be the category Applications where I have created three pages. Look first how it looks now and then delete/replace the code as shown below.

    Open the template categoryHeader and delete the whole content. Save.

    Open the template categoryFooter and delete the whole content. Save.

    Open the template categoryTable and add the following code:

    Spoiler
    
    <div class='ipsPad'  data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}' data-controller='core.global.core.table{{if $table->canModerate()}},core.front.core.moderation{{endif}}'>
    	{{if !count($rows)}}
    		<div class="ipsPad">
    			{lang="cms_no_records_to_show" sprintf="\IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId )->recordWord()"}
    		</div>
    	{{else}}
    		<ol class='ipsDataList ipsDataList_zebra ipsClear cCmsListing {{foreach $table->classes as $class}}{$class} {{endforeach}}' id='elTable_{$table->uniqueId}' data-role="tableRows">
    			{{foreach $rows as $row}}
    				{{$idField = $row::$databaseColumnId;}}
    				<li class="cDocs_row " data-rowid="{$row->$idField}">
    					<h4 class="ipsType_sectionHead">
    						<a href="{$row->url()}" class="ipsType_blendLinks">
    							{$row->_title}
    						</a>
    					</h4>
    					<div class="ipsType_normal ipsType_richText" data-ipstruncate="" data-ipstruncate-type="remove" data-ipstruncate-size="3 lines">
    						{$row->truncated()|raw}
    					</div>
    				</li>
    			{{endforeach}}
    		</ol>
    	{{endif}}
    </div>

     

    At this point the list of all pages in a category is created with text preview. This list will not be accessible later via the navigation. However, users from the search engines will land here, since category links are included in the sitemap.




  • Sign In and Stay Uptodate

    New articles and tutorials on how to monetize your community are on the way. To stay update sign in and subscribe to our newsletter. 

×
×
  • Create New...