lib_TWIG_box: usage
Since L* 3 you should take the lib_twig_box instead of the "register_parser"-technique for backend/frontend templates.
Its more easy and stable and more less of code at all.
Example:
lib_twig_box
A simple example from the module "display_code"
- $oTwig = lib_twig_box::getInstance();
- $oTwig->registerModule("display_code");
- echo $oTwig->render(
- "@display_code/modify.lte", // template-filename
- $form_values // template-data
- );
Listing 2.1 :: lib_twig_box example
See also
LEPTON_tools
last edit: 12. Mar 2024 CET 20:12:17
As you can see in listing above you will only have to
- [line 1]: get an (singelton) instance of the class.
- [line 2]: register your module so the Twig-Template-engine knows where to look for the used files. (inside the module folder or optional inside the frontend/theme template)
- [line 4 ff.]: render your files/data as you need
Marker (since L* 7.2.0)
Following marker are ready in lib_twig_box
{{ LEPTON_URL }}
{{ LEPTON_PATH }}
{{ ADMIN_URL }}
{{ THEME_PATH }}
{{ THEME_URL }}
{{ MEDIA_DIRECTORY }}
{{ PAGES_DIRECTORY }}
{{ PAGE_EXTENSION }}
{{ AUTH_MIN_LOGIN_LENGTH }}
{{ AUTH_MAX_LOGIN_LENGTH }}
{{ AUTH_MIN_PASS_LENGTH }}
{{ AUTH_MAX_PASS_LENGTH }}
<!-- Also the (global} language arrays are available -->
{{ TEXT }}
{{ MENU }}
{{ HEADING }}
{{ MESSAGE }}
{{ OVERVIEW }}
{{ THEME }}
<!-- only in frontend -->
{{ TEMPLATE_DIR }}
<!-- since L* 7.4 -->
{{ DEFAULT_TEMPLATE_URL }}
{{ DEFAULT_TEMPLATE_PATH }}
last edit: 07. Apr 2025 CEST 21:10:28
Available functions and filters
Only available in L*. (not full documentated yet) For details see:
<!-- ******** Functions ******** -->
[1] {{ getPasswordPattern() }}
[2] {{ getEmailPattern() }}
[3] {{ getDisplayPattern() }}
[4] {{ getPattern($sPattenType) }}
example
{{ getPattern('UserNames') }}
{{ getPattern('Email') }}
{{ getPattern('PassWord') }}
[5] {{ fileExists( anyFullLocalPath ) }}
example
{% if !fileExists( (AnyPath ~ AnyFilePart1 ~ '_' ~ AnyFilePart2 ~ '.pdf') ) %}
<!-- ******** Filters ******** -->
[1] {{ display( tagType, cssClass, useVarDump) }}
example
{{ getPasswordPattern()|display() }}
{{ 'hello world"|display('code') }}
{{ getPasswordPattern()|display('pre', 'ui message red', true) }}
[2] {{ CharsDecodeOutput() }}
example:
{{ array.any_marker|CharsDecodeOutput }}
[3] {{ intersects( arrayHayStack ) }}
example
{{ if array_needle|intersects(array_heystack) }} ... {{ endif }}
{{ set userHasAccess = array_needle|intersects(array_heystack) }}
[4] {{ timeF() }}
Force a time(-string) to display only HH:mm (e.g. "12:15")
Example given
a) "15:04:0001223" will be force to "15:04".
b) "15" will be force to "15:00".
c) NUll or empty string will be untouched!
d) A value of "0" will be forces to be "00:00".
example
{{ myTimeWithSeconds|timeF() }}
last edit: 07. Apr 2025 CEST 17:25:08