Download the PHP package oxid-esales/smarty-to-twig-converter without Composer

On this page you can find all versions of the php package oxid-esales/smarty-to-twig-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smarty-to-twig-converter

Converting Smarty templates to Twig

Converting tool located at GitHub allows to convert existing Smarty template files to Twig syntax. The tool besides standard Smarty syntax is adjusted to handle custom OXID modifications and extensions.

Installation

Clone the repository:

git clone https://github.com/OXID-eSales/smarty-to-twig-converter.git

Install dependencies:

cd smarty-to-twig-converter

composer install

Usage

The convert command tries to fix as much coding standards problems as possible on a given file, directory or database.

path and ext parameters

Converter can work with files and directories:

php toTwig convert --path=/path/to/dir php toTwig convert --path=/path/to/file

By default files with .html.twig extension will be created. To specify different extensions use --ext parameter:

php toTwig convert --path=/path/to/dir --ext=.js.twig

database and database-columns parameters

It also can work with databases:

php toTwig convert --database="mysql://user:password@localhost/db"

The --database parameter gets database doctrine-like URL. Converter by default converts following tables columns:

The --database-columns option lets you choose tables columns to be converted (the table column names has to be specified in table_a.column_b format and separated by comma):

php toTwig convert --database="..." --database-columns=oxactions.OXLONGDESC,oxcontents.OXCONTENT

You can also blacklist the table columns you don't want using -table_a.column_b:

php toTwig convert --database="..." --database-columns=-oxactions.OXLONGDESC_1,-oxcontents.OXCONTENT_1

converters parameter

The --converters option lets you choose the exact converters to apply (the converter names must be separated by a comma):

php toTwig convert --path=/path/to/dir --ext=.html.twig --converters=for,if,misc

You can also blacklist the converters you don't want if this is more convenient, using -name:

php toTwig convert --path=/path/to/dir --ext=.html.twig --converters=-for,-if

dry-run, verbose and diff parameters

A combination of --dry-run, --verbose and --diff will display summary of proposed changes, leaving your files unchanged.

All converters apply by default.

The --dry-run option displays the files that need to be fixed but without actually modifying them:

php toTwig convert --path=/path/to/code --ext=.html.twig --dry-run

config-path parameter

Instead of building long line commands it is possible to inject PHP configuration code. Two example files are included in main directory: config_file.php and config_database.php. To include config file use --config-path parameter:

php toTwig convert --config-path=config_file.php

Config script should return instance of toTwig\Config\ConfigInterface. It can be created using toTwig\Config\Config::create() static method.

Known issues

Converted plugins and syntax pieces

Here is list of plugins and syntax pieces with basic examples how it is converted. Note that these examples are only to show how it is converted and doesn't cover all possible cases as additional parameters, block nesting, repetitive calls (as for counter and cycle functions) etc.

Core Smarty

assign => set

Converter name: assign

Smarty:\ [{assign var="name" value="Bob"}]

Twig:\ {% set name = "Bob" %}

block => block

Converter name: block

Smarty:\ [{block name="title"}]Default Title[{/block}]

Twig:\ {% block title %}Default Title{% endblock %}

capture => set

Converter name: CaptureConverter

Smarty:\ [{capture name="foo" append="var"}] bar [{/capture}]

Twig:\ {% set foo %}{{ var }} bar {% endset %}

Comments

Converter name: comment

Smarty:\ [{* foo *}]

Twig:\ {# foo #}

counter => set

Converter name: counter

Smarty:\ [{counter}]

Twig:\ {% set defaultCounter = ( defaultCounter|default(0) ) + 1 %}

cycle => smarty_cycle

Converter name: cycle

Smarty:\ [{cycle values="val1,val2,val3"}]

Twig:\ {{ smarty_cycle(["val1", "val2", "val3"]) }}

foreach => for

Converter name: for

Smarty:\ [{foreach $myColors as $color}]foo[{/foreach}]

Twig:\ {% for color in myColors %}foo{% endfor %}

if => if

Converter name: if

Smarty:\ [{if !$foo or $foo->bar or $foo|bar:foo["hello"]}]foo[{/if}]

Twig:\ {% if not foo or foo.bar or foo|bar(foo["hello"]) %}foo{% endif %}

include => include

Converter name: include

Smarty:\ [{include file='page_header.tpl'}]

Twig:\ {% include 'page_header.tpl' %}

insert => include

Converter name: insert

Smarty:\ [{insert name="oxid_tracker" title="PRODUCT_DETAILS"|oxmultilangassign product=$oDetailsProduct cpath=$oView->getCatTreePath()}]

Twig:\ {% include "oxid_tracker" with {title: "PRODUCT_DETAILS"|oxmultilangassign, product: oDetailsProduct, cpath: oView.getCatTreePath()} %}

mailto => mailto

Converter name: mailto

Smarty:\ [{mailto address='[email protected]'}]

Twig:\ {{ mailto('[email protected]') }}

math => core Twig math syntax

Converter name: math

Smarty:\ [{math equation="x + y" x=1 y=2}]

Twig:\ {{ 1 + 2 }}

Variable conversion

Converter name: variable

Smarty Twig
[{$var}] {{ var }}
[{$contacts.fax}] {{ contacts.fax }}
[{$contacts[0]}] {{ contacts[0] }}
[{$contacts[2][0]}] {{ contacts[2][0] }}
[{$person->name}] {{ person.name }}
[{$oViewConf->getUrl($sUrl)}] {{ oViewConf.getUrl(sUrl) }}
[{($a && $b) || $c}] {{ (a and b) or c }}

Other

Converter name: misc

Smarty Twig
[{ldelim}]foo[{ldelim}] foo
[{literal}]foo[{/literal}] {# literal #}foo{# /literal #}
[{strip}]foo[{/strip}] {% spaceless %}foo{% endspaceless %}

OXID custom extensions

oxcontent => include_content

Converter name: oxcontent

Smarty:\ [{oxcontent ident='oxregisteremail'}]

Twig:\ {% include_content 'oxregisteremail' %}

oxeval => include(template_from_string())

Converter name: OxevalConverter

Smarty:\ [{oxeval var=$variable}]

Twig:\ {{ include(template_from_string(variable)) }}

oxgetseourl => seo_url

Converter name: oxgetseourl

Smarty:\ [{oxgetseourl ident=$oViewConf->getSelfLink()|cat:"cl=basket"}]

Twig:\ {{ seo_url({ ident: oViewConf.getSelfLink()|cat("cl=basket") }) }}

oxhasrights => hasrights

Converter name: oxhasrights

Smarty:\ [{oxhasrights object=$edit readonly=$readonly}]foo[{/oxhasrights}]

Twig:\ {% hasrights { "object": "edit", "readonly": "readonly", } %}foo{% endhasrights %}

oxid_include_dynamic => include_dynamic

Converter name: oxid_include_dynamic

Smarty:\ [{oxid_include_dynamic file="form/formparams.tpl"}]

Twig:\ {% include_dynamic "form/formparams.tpl" %}

oxid_include_widget => include_widget

Converter name: oxid_include_widget

Smarty:\ [{oxid_include_widget cl="oxwCategoryTree" cnid=$oView->getCategoryId() deepLevel=0 noscript=1 nocookie=1}]

Twig:\ {{ include_widget({ cl: "oxwCategoryTree", cnid: oView.getCategoryId(), deepLevel: 0, noscript: 1, nocookie: 1 }) }}

oxifcontent => ifcontent

Converter name: oxifcontent

Smarty:\ [{oxifcontent ident="TOBASKET" object="aObject"}]foo[{/oxifcontent}]

Twig:\ {% ifcontent ident "TOBASKET" set aObject %}foo{% endifcontent %}

oxinputhelp => include "inputhelp.tpl"

Converter name: oxinputhelp

Smarty:\ [{oxinputhelp ident="foo"}]

Twig:\ {% include "inputhelp.tpl" with {'sHelpId': getSHelpId(foo), 'sHelpText': getSHelpText(foo)} %}

oxmailto => oxmailto

Converter name: oxmailto

Smarty:\ [{oxmailto address='[email protected]'}]

Twig:\ {{ mailto('[email protected]') }}

oxmultilang => translate

Converter name: oxmultilang

Smarty:\ [{oxmultilang ident="ERROR_404"}]

Twig:\ {{ translate({ ident: "ERROR_404" }) }}

oxprice => format_price

Converter name: oxprice

Smarty:\ [{oxprice price=$basketitem->getUnitPrice() currency=$currency}]

Twig:\ {{ format_price(basketitem.getUnitPrice(), { currency: currency }) }}

oxscript => script

Converter name: oxscript

Smarty:\ [{oxscript include="js/pages/details.min.js" priority=10}]

Twig:\ {{ script({ include: "js/pages/details.min.js", priority: 10, dynamic: __oxid_include_dynamic }) }}

oxstyle => style

Converter name: oxstyle

Smarty:\ [{oxstyle include="css/libs/chosen/chosen.min.css"}]

Twig:\ {{ style({ include: "css/libs/chosen/chosen.min.css" }) }}

section => for

Converter name: section

Smarty:\ [{section name=picRow start=1 loop=10}]foo[{/section}]

Twig:\ {% for picRow in 1..10 %}foo{% endfor %}

Filters

Smarty Twig
smartwordwrap smart_wordwrap
date_format date_format
oxaddparams add_url_parameters
oxaddslashes addslashes
oxenclose enclose
oxfilesize file_size
oxformattime format_time
oxformdate format_date
oxmultilangassign translate
oxmultilangsal translate_salutation
oxnubmerformat format_currency
oxtruncate truncate
oxwordwrap wordwrap

Running database conversion PHPUnit tests

Note for CI: To run database conversion PHPUnit tests, sqlite is required. You can install it by running following commands:

$ sudo apt-get install sqlite3
$ sudo apt-get install php7.2-sqlite

Bugs and Issues

If you experience any bugs or issues, please report them in the section OXID eShop (all versions) under category Twig engine of https://bugs.oxid-esales.com


All versions of smarty-to-twig-converter with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
symfony/console Version ~2.1
symfony/filesystem Version ~2.1
symfony/finder Version ~2.1
sebastian/diff Version 2.*
phpunit/phpunit Version ^6
doctrine/dbal Version ^2.9
phpunit/dbunit Version 3.*
ext-dom Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oxid-esales/smarty-to-twig-converter contains the following files

Loading the files please wait ....