Twig Template Engine For Opencart
Twig is a modern template engine for PHP
Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum.
Secure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
Flexible: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL.
-
Upload the folders and files from the 'upload' directory via FTP to your OpenCart server's main directory. No files will be replaced
-
Log into the admin backend, proceed to Extensions > Installer, click on the Upload button and browse to vanderson_twig_ocmod.xml file.
-
Proceed to Extensions > Modifications, and click on the Refresh button located near the top right corner.
-
Use $this->load->view('template_path') on controllers to compile with twig, native php templates or both mixed.
-
By default, cache is disabled. If you want to use cache, define the path variable on config.php and admin/config.php files:
define('TWIG_CACHE', DIR_CACHE . 'twig');
##Functions##
Shortcut for $this->url->link();
Params:
- route
- args
- ssl
{{ link('product/product', { 'foo': 'bar' }, 'SSL') }}
- param 'token' is automatically placed
Loads the corrensponding language string
Params:
- key
- file
{{ lang('text_yes') }}
{{ lang('text_stock', 'product/product') }}
Gets config value
Params:
- key
- file
{{ config('config_name') }}
{{ config('custom_config', 'custom_file') }}
Resize the image and return its url
Params:
- path
- context
- width
- height
<img src="{{ image('catalog/Your-Image.png') }}" />
<img src="{{ image('catalog/Your-Image.png', 'thumb') }}" />
Generate link to the file
Params:
- path
<script src="{{ asset('javascript/bootstrap.js') }}" ></script>
Loads a controller
Params:
- path
{{ load('common/column_left') }}
Render a pagination view
Params:
- total
- limit
- route
- args
- template
{{ paginate(50, 5, 'product/category') }}
{{ paginate(50, 5, 'product/category', { 'foo': 'bar' }, 'custom_template/pagination.twig') }}
Check if the logged user can access the resource
Params:
- key
{% if can_access('user/user_permission') %}
{# Can access this resource #}
{% endif %}
Check if the logged user can modify the resource
Params:
- key
{% if can_modify('user/user_permission') %}
{# Can modify this resource #}
{% endif %}
Shortcut for $this->currency->format()
Params:
- currency
- value
- format
{{ product.price|money }}
Shortcut for $this->tax->calculate()
Params:
- tax_class_id
- calculate
{{ product.price|tax(product.tax_class_id) }}
Shortcut for $this->length->format()
Params:
- length_class_id
- decimal_point
- thousand_point
{{ product.length|len(product.length_class_id) }}
Shortcut for $this->weight->format()
Params:
- weight_class_id
- decimal_point
- thousand_point
{{ product.weight|wei(product.weight_class_id) }}
Limits the text based on config 'config_product_description_length'
Params:
- suffix
- limit
{{ product.description|truncate('...', 50) }}
Shortcut for Encryption->encrypt()
{{ 'foo'|encrypt }}
Shortcut for Encryption->decrypt()
{{ 'SUEfGT636cD1VNzqs-avGhuKx2w4suvPJ18k9qCYdws,'|decrypt }}
This variables are accessible in all twig templates
- document_title
- document_description
- document_keywords
- document_links
- document_styles
- document_scripts
- route
- is_logged
- user
- customer
- affiliate
- is_affiliate_logged
- cart