-
Notifications
You must be signed in to change notification settings - Fork 1
CMS Service
The target of the CMS Service is to grant the compatibility to the existing functions provided by the different Content Management Systems. If you have already created templates for WebsiteBaker, LEPTON CMS or BlackCat CMS you will already know some of the following functions:
$template['cms']->cms_modified_by()
$template['cms']->cms_modified_when()
$template['cms']->page_content()
$template['cms']->page_description()
$template['cms']->page_footer()
$template['cms']->page_has_child()
$template['cms']->page_header()
$template['cms']->page_image()
$template['cms']->page_keywords()
$template['cms']->page_modified_by()
$template['cms']->page_modified_when()
$template['cms']->page_next_id()
$template['cms']->page_option()
$template['cms']->page_previous_id()
$template['cms']->page_sequence()
$template['cms']->page_title()
$template['cms']->page_url()
$template['cms']->register_frontend_modfiles()
$template['cms']->register_frontend_modfiles_body()
$template['cms']->show_menu2()
$template['cms']->wysiwyg_content()
$template['cms']->wysiwyg_section_ids()
most of these functions can directly prompt the result using echo
(which is the general behavior of the origin functions provided by the different CMS), but they can also return the result without prompting.
Some functions are new, like page_url()
and page_option()
or provide you with extended features like page_title()
or page_content()
.
All functions can also used within Twig Templates, just place the function name between the delimiters {{ ... }}
, for example:
{{ page_content() }}
Parameter
-
string $locale
- optional, default =null
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->cms_modified_by(); ?>
Usage twig
{{ cms_modified_by() }}
This function will return the displayname of the user who has last modified any page of the Content Management System (CMS). You can also specify the locale to use.
See also
Parameter
-
string $format
- optional, default ='DATETIME_FORMAT'
-
string $locale
- optional, default =null
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->cms_modified_when(); ?>
Usage twig
{{ cms_modified_when() }}
This function will return the date and time of the last modification of any page in the Content Management System (CMS). You can also specify the format of the date and time stamp and the locale to use.
Example php
:
<?php $template['cms']->cms_modified_when('Y-m-d'); ?>
will return something like 2014-05-16
. The format can be a locale string which will be translated, i.e. from
/kit2/extension/phpmanufaktur/phpManufaktur/Data/Locale/Metric
like the predefined 'DATETIME_FORMAT'
or 'DATE_FORMAT'
or 'TIME_FORMAT'
or it can be any formatting string for the php
function date()
.
See also
Parameter
-
integer|string $block
- optional, default =1
-
boolean $prompt
- optional, default =true
(php
only) -
array $option
- optional, default =array()
Usage php
<?php $template['cms']->page_content(); ?>
Usage twig
{{ page_content() }}
If you are using content blocks you can specify the block to prompt:
<?php $template['cms']->page_content(2); ?>
will prompt the second block defined in the info.php
of the template.
<?php $my_block = $template['cms']->page_content(2, true, false); ?>
will return the second block into the variable $my_block
without prompting the content.
In different to origin usage of the parameter $block
you can also use the name of the block definition. If you info.php
does contain:
$block[1] = 'Main Content';
$block[2] = 'Sidebar';
you can also use:
<?php $template['cms']->page_content('Sidebar'); ?>
to load the content of the Sidebar
block. This increase the readability of your templates.
If you have installed kitFramework imageTweak, the function page_content()
will automatically parse and optimize the embedded images. Use the config.imagetweak.json
configuration file to disable imageTweak or set the $option
for imageTweak to false
:
<?php $template['cms']->page_content('Sidebar', true, array('image_tweak' => false)); ?>
or in a twig
template:
{{ page_content('Sidebar', {'image_tweak':false}) }}
If you are using the TemplateTools, you should not add the imageTweak filter command to your template!
Parameter
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_description(); ?>
Usage twig
{{ page_description() }}
The function will return the description for the actual [[PAGE_ID
|Constants#page_id]], see also [[PAGE_DESCRIPTION
|Constants#page_description]].
page_description()
automatically detects TOPICS, NEWS and flexContent Articles and will return fitting descriptions.
Parameter
-
string $date_format
- optional, default =Y
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_footer(); ?>
Usage twig
{{ page_footer() }}
The function will return the parsed Website Footer, see also [[PAGE_FOOTER
|Constants#page_footer]].
You can use the placeholders [YEAR]
and [PROCESS_TIME]
in the definition for the Website Footer:
-
[YEAR]
will be replaced with the current date and formatted as specified in$date_format
-
[PROCESS_TIME]
will be replaced with seconds needed to render the actual page (not very precise).
Parameter
-
integer $page_id
- optional, default =PAGE_ID
´ (ID of the current page) -
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_has_child(); ?>
This function will return true
if the given $page_id
has a child, see also PAGE_HAS_CHILD
.
Parameter
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_header(); ?>
Usage twig
{{ page_header() }}
This function will return the Website Header, see also [[PAGE_HEADER
|Constants#page_header]].
Parameter
-
integer $page_id
- optional, defaultPAGE_ID
-
array $options
- optional, defaultarray()
Usage php
<?php $template['cms']->page_image(); ?>
Usage twig
{{ page_image() }}
This function return the URL of first image of a WYSIWYG section, NEWS, TOPICS or flexContent article or a TOPICS or a flexContent Teaser image.
Needed for the Open Graph Support.
If no image exists, the function return an empty string.
You can place a fallback image /image/page_image.png
in your template directory, this image will be taken if no other image was detected.
The $options
array can be used to specify the behavior:
<?php $template['cms']->page_image(PAGE_ID, array(
'fallback_image' => array(
'active' => true,
'url' => TEMPLATE_URL.'/image/page_image.png'
),
'minimum_size' => array(
'width' => 200,
'height' => 150
)
)); ?>
By default images must be at minimum 200 pixels width and 150 pixels height.
Parameter
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_keywords(); ?>
Usage twig
{{ page_keywords() }}
The function will return the keywords for the actual [[PAGE_ID
|Constants#page_id]], see also PAGE_KEYWORDS
.
page_keywords()
automatically detects TOPICS, NEWS and flexContent Articles and will return fitting descriptions.
Parameter
-
integer $page_id
- optional, default =PAGE_ID
-
string $locale
- optional, default =null
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_modified_by(); ?>
Usage twig
{{ page_modified_by() }}
This function will return the displayname of the user who has last modified the current page. You can also specify a page ID
and the locale to use.
Example php
:
<?php $template['cms']->page_modified_by(23); ?>
will return displayname of the user who has last modified the page with the ID
23
.
See also
Parameter
-
integer $page_id
- optional, default =PAGE_ID
-
string $format
- optional, default ='DATETIME_FORMAT'
-
string $locale
- optional, default =null
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_modified_when(); ?>
Usage twig
{{ page_modified_when() }}
This function will return the date and time the current page has last modified. You can also specify the format of the date and time stamp, a page ID
and the locale to use.
Example php
:
<?php $template['cms']->page_modified_when(PAGE_ID, 'Y-m-d'); ?>
will return something like 2014-05-16
. The format can be locale string which will be translated, i.e. from
/kit2/extension/phpmanufaktur/phpManufaktur/Data/Locale/Metric
like the predefined 'DATETIME_FORMAT'
or 'DATE_FORMAT'
or 'TIME_FORMAT'
or it can be any formatting string for the php
function date()
.
See also
Parameter
-
integer $page_id
- optional, default =PAGE_ID
-
array $visibility
- optional, default =array('public')
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_next_id(); ?>
Usage twig
as Function
{{ page_next_id() }}
The function will return by default the ID of the next following page of the current page.
Example:
{{ page_next_id(34, ['public','hidden']) }}
will show next page following to the page ID 34
which is public
or hidden
.
See also:
Parameter
-
string $option
- the option to select -
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_option('sample'); ?>
Usage twig
as Function
{{ page_option('sample') }}
Neither WebsiteBaker, LEPTON CMS nor Black CMS offer a possibility to set individual Options for a page. But sometimes you need exactly this feature in your template, for example to set a class to indicate a special offer or to show or hide a Sidebar ...
If you are using the TemplateTools you can add Options to the Keywords setting field of the pages:
- Options must be set as first entry in the Keywords field
-
Options must be enclosed by
[
square brackets]
- Options must be separated by comma from the Keywords
- each Option Pair must be defined by schema:
key:value
(Key followed by a Colon and then the Value) - multiple Option Pairs must be separated by a
|
Pipe
Example, type in the Keywords field:
[sample:This is a sample value], Keyword one, Keyword two
and save it. This will set the Option Key sample
with the Option Value This is a sample value
.
Using page_keywords()
in your template (php
example):
<meta name="keywords" content="<?php $template['cms']->page_keywords(); ?>" />
will output:
<meta name="keywords" content="Keyword one, Keyword two" />
without the additional Options (this is important!).
With the function page_option()
you can access the Option:
<?php page_option('sample'); ?>
will prompt:
This is a sample value
You can also define multiple Option Pairs in the Keywords field, separate them by a |
:
[color_one:Yellow|color_two:Blue], Keyword one, Keyword two
will set the Option Keys color_one
and color_two
, you can access them (twig
example):
<p>Option one: {{ page_option('color_one') }} and Option two: {{ page_option('color_two') }}</p>
If a Option Key does not exists, the TemplateTools will return null
, so you can check for null
in your Template to validate a key (php
example):
<?php
if (!is_null($template['cms']->page_option('color_one')) {
// the option 'color_one' exists, do something
$template['cms']->page_option('color_one');
}
?>
twig
example:
{% if page_option('color_one') is not null %}
{# the option 'color_one' exists, do something #}
{{ page_option('color_one') }}
{% endif %}
Parameter
-
integer $page_id
- optional, default = [[PAGE_ID
|Constants#page_id]] -
array $visibility
- optional, default =array('public')
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_previous_id(); ?>
Usage twig
as Function
{{ page_previous_id() }}
The function will return by default the ID of the previous page to the current page.
Example:
<?php $previous_id = $template['cms']->page_previous_id(34,
array('public', 'hidden'), true); ?>
will show previous page for the page ID 34
which is public
or hidden
.
See also: page_next_id()
Parameter
-
integer $menu
- optional, default =1
, -
integer $start_level
- optional, default =0
, -
array $visibility
- optional, default =array('public')
Usage php
only:
<?php $sequence = $template['cms']->page_sequence(); ?>
This function will return an array with all page ID's in logical sequence through all levels in correct position order. Can be used to build previous / next buttons or to create a Sitemap. The function support up to 10 menu levels at maximum.
Parameter
-
string $spacer
- optional, default =' - '
-
string $template
- optional, default ='[PAGE_TITLE]'
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_title(); ?>
Usage twig
{{ page_title() }}
The function will return the formatted page title for the current [[PAGE_ID
|Constants#page_id]], see also [[PAGE_TITLE
|Constants#page_title]].
You define your own $spacer
and $template
. page_title()
supports the following placeholders in $template
:
-
[PAGE_TITLE]
- the page title -
[SPACER]
- the defined$spacer
-
[MENU_TITLE]
- the menu title of the current page -
[WEBSITE_TITLE]
- the Website Title
Assume, the Website Title is defined as My fancy website
and the title of the current page is Bubblegum
, then:
<?php $template['cms']->page_title(' - ', '[WEBSITE_TITLE][SPACER][PAGE_TITLE]'); ?>
or alternate in twig
:
{{ page_title(' - ', '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') }}
will prompt:
My fancy website - Bubblegum
page_title()
automatically detects TOPICS, NEWS and flexContent Articles and will return fitting descriptions.
Parameter
-
integer $page_id
- optional, default = [[PAGE_ID
|Constants#page_id]] -
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->page_url(); ?>
Usage twig
{{ page_url() }}
The function return by default the URL for the current page by [[PAGE_ID
|Constants#page_id]].
###register_frontend_modfiles()
Parameter
-
string $file_type
- optional, default =css
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->register_frontend_modfiles(); ?>
Usage twig
{{ register_frontend_modfiles() }}
This function gather frontend.css
or frontend.js
files from the /modules
directory of the CMS to include them in the <head>
section of the template.
<?php $template['cms']->register_frontend_modfiles('css'); ?>
<?php $template['cms']->register_frontend_modfiles('js'); ?>
or
{{ register_frontend_modfiles('js') }}
{{ register_frontend_modfiles('css') }}
will create <script> ... </script>
tags for the detected frontend.js
and frontend.css
files.
The origin function register_frontend_modfiles()
can also include jQuery base files if $file_type
is jquery
. It is not recommend to include jQuery in such way - the jQuery inclusion is not actual and may cause a couple of problems, please use the LibraryAdmin or the jQuery support of the TemplateTools instead! For this reason the support for jquery
is disabled for the function register_frontend_modfiles()
inside of the TemplateTools.
###register_frontend_modfiles_body()
Parameter
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->register_frontend_modfiles_body(); ?>
Usage twig
{{ register_frontend_modfiles() }}
This function gather frontend_body.js
files from the /modules
directory of the CMS to include them before the </body>
tag of the template.
In different to the origin function register_frontend_modfiles_body()
this function does not include any jQuery files into the <head>
section of the template. See also the hint in register_frontend_modfiles()
.
Parameter
-
integer|string $aMenu
- optional, default =0
-
integer $aStart
- optional, default =SM2_ROOT
-
integer $aMaxLevel
- optional, default =SM2_CURR+1
-
integer $aOptions
- optional, default =SM2_TRIM
-
string $aItemOpen
- optional, default ='[li][a][menu_title]</a>'
-
string $aItemClose
- optional, default ='</li>'
-
string $aMenuOpen
- optional, default ='[ul]'
-
string $aMenuClose
- optional, default ='</ul>'
-
boolean $aTopItemOpen
- optional, default =false
-
boolean $aTopMenuOpen
- optional, default =false
-
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->show_menu2(); ?>
Usage twig
{{ show_menu2() }}
show_menu2()
is well documented, please use the online documentation for further information to the usage of show_menu2()
.
ATTENTION: show_menu2()
is using the bitwise or
Operator |
(pipe) to combine flags. You can not use the pipe |
as bitwise or
Operator in Twig, you must use b-or
instead!
Example, if you need something like:
show_menu2(0, SM2_ROOT, SM2_ALL, SM2_ALL|SM2_NUMCLASS|SM2_PRETTY)
you must use instead:
show_menu2(0, SM2_ROOT, SM2_ALL, SM2_ALL b-or SM2_NUMCLASS b-or SM2_PRETTY)
The TemplateTools add the parameter $prompt
at the last position, if you set this parameter to false
, the function will return the result as string:
$my_menu = $template['cms']->show_menu2(0, SM2_ROOT, SM2_CURR+1, SM2_TRIM,
'[li][a][menu_title]</a>', '</li>', '[ul]', '</ul>', false, false, false);
See also [[Constants for show_menu2()
|Constants#show_menu2]]
In different to origin usage of the parameter $aMenu
you can also use the name of the menu definition and not only the integer value. If you info.php
does contain:
$menu[1] = 'Main Navigation';
$menu[2] = 'Footer Navigation';
you can also use:
<?php $template['cms']->show_menu2('Footer Navigation'); ?>
to access the Footer Navigation
menu. This increase the readability of your templates.
Parameter
-
integer $section_id
- the SECTION ID to use -
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['cms']->wysiwyg_content(99); ?>
Usage twig
{{ wysiwyg_content(99) }}
The function return the content of a WYSIWYG Section.
Parameter
-
integer $page_id
- optional, the page ID to use, default =PAGE_ID
-
integer|string $block_id
- optional, the block to select, default =1
-
string $order
- optional, the order of the sections, default ='ASC'
Usage php
<?php $section_ids = $template['cms']->wysiwyg_section_ids(); ?>
Usage twig
{% set section_ids = wysiwyg_section_ids() %}
The function return the section ID's for the given page ID and Block ID in the specified order.
The block can be an integer or the name of the block. The order can be ascending 'ASC'
(default), descending 'DESC'
or randomized 'RANDOM'
.
Example twig
:
{% set section_ids = wysiwyg_section_ids(PAGE_ID_HOME, 'Teaser', 'RANDOM') %}
{% if section_ids is not null and section_ids|length > 0 %}
{% for section_id in section_ids %}
<div class="teaser">{{ wysiwyg_content(section_id) }}</div>
{% endfor %}
{% endfor %}
Will select the WYSIWYG sections 'Teaser'
in randomized order from the Homepage and display them at the current page.
- If you spot a typo or want to contribute an article, a how-to or a tip, feel free to edit the Wiki directly
- If you you have any questions, please visit the phpManufaktur Support Forum
This Documentation is part of the kitFramework Project
© 2014 by phpManufaktur, kitFramework and TemplateTools are published under MIT license.