-
Notifications
You must be signed in to change notification settings - Fork 1
Tools Service
The Tools Service is a collection of functions which are needed by the TemplateTools itself or which are useful for Template Designers and does not fit to any other Service.
$template['tools']->addLanguageFiles()
$template['tools']->ellipsis()
$template['tools']->get_first_header()
$template['tools']->humanize()
$template['tools']->readJSON()
$template['tools']->remove_first_header()
$template['tools']->sanitizePath()
$template['tools']->sanitizeText()
$template['tools']->unsanitizeText()
All of these functions are available within your php
template script, some of the functions are also available as twig
Function or Filter.
The Template Tools support a Translation Service, you can use this function to add language files for your template to the Translator:
<?php $template['tools']->addLanguageFiles(TEMPLATE_PATH.'/locale'); ?>
will add all language files from the /locale
directory to the Translator.
Parameter
-
string $text
- text which should be shortened -
integer $length
- optional, default =100
, the max. length of the result
Usage php
<?php $template['cms']->ellipsis('Some text ... which is very, very long'); ?>
Usage twig
(as Filter)
{{ 'Some text ... which is very, very long'|ellipsis }}
Usage twig
(as Function)
{{ ellipsis('Some text ... which is very, very long') }}
This will output a string, which is shortened to the maximum $length
and ...
(three dots, ellipsis) at the end.
The ellipsis()
function is in progress ... please check the documentation again in the near future!
Parameter
-
string $content
- HTML content to parse
Usage php
<?php
$content = $template['cms']->wysiwyg_content(12);
$header = $template['tools']->get_first_header($content);
// do something with the header ...
echo $header;
?>
Usage twig
(as Function)
{% set content = wysiwyg_content(12) %}
{% header = get_first_header(content) %}
{# do something with the header ... #}
{{ header }}
This function return the first <h1>
, <h2>
or <h3>
header of the submitted HTML content without the embedding tags.
Parameter
-
string $text
- text which should be humanized -
boolean $prompt
- optional, default =true
(php
only)
Usage php
<?php $template['tools']->humanize('EXAMPLE_IDENTIFIER'); ?>
Usage twig
(as Filter)
{{ 'EXAMPLE_IDENTIFIER'|humanize }}
Usage twig
(as Function)
{{ humanize('EXAMPLE_IDENTIFIER') }}
This will output the $text
in a humanized form:
Example identifier
This function uppercase the first character of the string and lowercase all others. Underscores _
will be replaced by single spaces.
Parameter
-
string $path
- full path to the JSON encoded file
Usage php
(Example):
<?php
// read the JSON file - the CMS information in this case
$json = $template['tools']->readJSON(MANUFAKTUR_PATH.'/Basic/config/cms.json');
// do something with the returned $json array
echo "<pre>";
print_r($json);
echo "</pre>";
?>
This function read a JSON file from the given path and return the content as associated array.
Parameter
-
string $content
- HTML content to parse
Usage php
<?php
$content = $template['cms']->wysiwyg_content(12);
$content = $template['tools']->remove_first_header($content);
// do something with the content ...
echo $content;
?>
Usage twig
(as Function)
{% set content = wysiwyg_content(12) %}
{% content = get_first_header(content) %}
{# do something with the content ... #}
{{ content }}
This function remove the first <h1>
, <h2>
or <h3>
header of the submitted HTML and return the changed content.
Parameter
-
string $path
- path to sanitize
Usage php
(Example):
<?php
$path = $template['tools']->sanitizePath($origin_path);
// do something with the sanitized $path
...
?>
This function will return a cleaned, sanitized path.
Parameter
-
string $text
- text to sanitize
Usage php
(Example):
<?php
$text = $template['tools']->sanitizeText($origin_text);
// do something with the sanitized $text
...
?>
The function return a sanitized $text
and convert HTML tags to their ISO-8859-1 equivalents and escape the the string, this is important to prevent a code injection.
See also: Code injection
See also: unsanitizeText()
Parameter
-
string $text
- text to unsanitize
Usage php
(Example):
<?php
$text = $template['tools']->unsanitizeText($origin_text);
// do something with the unsanitized $text
...
?>
The function revert sanitized text to executable HTML or other code. In general all text information you read from the database will be sanitized and must be unsanitized before you can use the information.
See also: Code injection
See also: sanitizeText()
- 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.