Download the PHP package andrew72ru/bitrix-twig without Composer
On this page you can find all versions of the php package andrew72ru/bitrix-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrew72ru/bitrix-twig
More information about andrew72ru/bitrix-twig
Files in andrew72ru/bitrix-twig
Package bitrix-twig
Short Description Twig renderer for bitrix framework
License MIT
Informations about the package bitrix-twig
BITRIX/TWIG
Module for rendering twig templates in bitrix framework
rus
Intro
Bitrix framework allows render content with third-party template engines, in particular, twig.
To implement this, bitrix required a global (sic!) array $arCustomTemplateEngines
with next structure:
The templateExt
key describes extensions of template files, and in function
key of this array contains the global (sic!) function name, which implement the render of template.
Also, function must instantiate the template engine class and echo (yes, fucking echo, not return!) the result of rendering.
If you even feel headache because of this, wait a minute, this is not all.
Installation
You MUST use the composer autoloader in application init. You site MUST use utf-8 codepage.
To install module, simple run
Module will be stored in you vendor
, register it classes and functions.
Configuration
Default configuration:
You may override or extend this configuration in bitrix/.settings.php
file. The configuration key is twigRenderer
. You config may be like this:
Usage
Simple place the file <component_template_name>.thml.twig
(or <component_template_name>.twig
) to you template folder, instead of <component_template_name>.php
. All html-markup and twig functions / filters will be processed by twig engine. Module implement some custom functions to integrate template engine and bitrix framework (see below).
Custom twig variables functions
Global variables:
$_SERVER
—_SERVER
;$_REQUEST
—_REQUEST
;$_GET
—_GET
;$_POST
—_POST
;$_FILES
—_FILES
;$_SESSION
—_SESSION
;$_COOKIE
—_COOKIE
;$_GLOBALS
—_GLOBALS
Custom functions
showError
showMessage
showNote
bitrix_sessid_post
bitrix_sessid_get
getMessage
include_component
All of this the same bitrix framework functions.
_call_static($class, $method, $arguments = [])
is the function to call static method from available class from framework kernel or autoloaded classes.
Variables in template
result
—$arResult
in traditional template;params
—$arParams
in traditional template;lang
— array with all loaded localized messages;template
— instance ofCBitrixComponentTemplate
class;templateFolder
— path to template folder;parentTemplateFolder
— path to folder of parent template;
Events
The module call the onAfterTwigEngineInit
event after initialization. You may use it for add you own functions / filters / extensions.
Tests
Now the test contains a minimal (example) test, because of bitrix framework not have a psr autoloader, service container and other framework-must-have thinks. Tests are possible only if you have installed framework, installed module and at least one template, renders by this module.
If you know how to make test for all of classes — you welcome.