Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

vanderson139/opencart-twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

opencart-twig

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.

Installation

  • 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');

Documentation

##Functions##

link

Shortcut for $this->url->link();

Params:

  • route
  • args
  • ssl
    {{ link('product/product', { 'foo': 'bar' }, 'SSL') }}
  • param 'token' is automatically placed

lang

Loads the corrensponding language string

Params:

  • key
  • file
    {{ lang('text_yes') }}

    {{ lang('text_stock', 'product/product') }}

config

Gets config value

Params:

  • key
  • file
    {{ config('config_name') }}

    {{ config('custom_config', 'custom_file') }}

image

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') }}" />

asset

Generate link to the file

Params:

  • path
    <script src="{{ asset('javascript/bootstrap.js') }}" ></script>

load

Loads a controller

Params:

  • path
    {{ load('common/column_left') }}

paginate

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') }}

Admin only

can_access

Check if the logged user can access the resource

Params:

  • key
    {% if can_access('user/user_permission') %}

        {#  Can access this resource  #}

    {% endif %}

can_modify

Check if the logged user can modify the resource

Params:

  • key
    {% if can_modify('user/user_permission') %}

        {# Can modify this resource #}

    {% endif %}

Filters

money

Shortcut for $this->currency->format()

Params:

  • currency
  • value
  • format
    {{ product.price|money }}

tax

Shortcut for $this->tax->calculate()

Params:

  • tax_class_id
  • calculate
    {{ product.price|tax(product.tax_class_id) }}

len

Shortcut for $this->length->format()

Params:

  • length_class_id
  • decimal_point
  • thousand_point
    {{ product.length|len(product.length_class_id) }}

wei

Shortcut for $this->weight->format()

Params:

  • weight_class_id
  • decimal_point
  • thousand_point
    {{ product.weight|wei(product.weight_class_id) }}

truncate

Limits the text based on config 'config_product_description_length'

Params:

  • suffix
  • limit
    {{ product.description|truncate('...', 50) }}

encrypt

Shortcut for Encryption->encrypt()

    {{ 'foo'|encrypt }}

decrypt

Shortcut for Encryption->decrypt()

    {{ 'SUEfGT636cD1VNzqs-avGhuKx2w4suvPJ18k9qCYdws,'|decrypt }}

Globals

This variables are accessible in all twig templates

  • document_title
  • document_description
  • document_keywords
  • document_links
  • document_styles
  • document_scripts
  • route
  • is_logged

Admin Only

  • user

Catalog Only

  • customer
  • affiliate
  • is_affiliate_logged
  • cart

alt tag

About

Twig Template Engine For Opencart - OCMOD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages