### Clone and Install Dependencies (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command clones the repository from GitHub and installs the necessary PHP dependencies using Composer. This is a prerequisite for using the Smarty to Twig converter. ```shell git clone https://github.com/OXID-eSales/smarty-to-twig-converter.git cd smarty-to-twig-converter composer install ``` -------------------------------- ### File-based Configuration (PHP) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Defines conversion rules and settings using a PHP configuration file for file-based template conversion. This approach allows for more complex setups, including custom finders and output extensions, managed programmatically. The `--config-path` option points to this configuration file. ```php in('templates') ->name('*.tpl'); $sourceConverter = new \toTwig\SourceConverter\FileConverter(); $sourceConverter ->setFinder($finder) ->setOutputExtension('.html.twig'); return \toTwig\Config\Config::create() ->setSourceConverter($sourceConverter); ``` ```bash php toTwig convert --config-path=config_file.php ``` -------------------------------- ### Programmatic File Conversion (PHP) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates how to use the Smarty to Twig converter library programmatically in PHP. This example shows basic file conversion, registering built-in converters, setting up a file source converter, and processing the conversion results, including diffs. It provides a foundation for integrating the converter into larger PHP applications. ```php registerBuiltInConverters(); $sourceConverter = new FileConverter(); $sourceConverter->setPath('/path/to/templates'); $sourceConverter->setOutputExtension('.html.twig'); $converter->setSourceConverter($sourceConverter); // Perform conversion $results = $converter->convert($dryRun = false, $diff = true); // Process results foreach ($results as $filename => $conversionResult) { echo "Converted: {$filename}\n"; echo "Applied converters: " . implode(', ', $conversionResult->getAppliedConverters()) . "\n"; if ($conversionResult->getDiff()) { echo $conversionResult->getDiff() . "\n"; } } ``` -------------------------------- ### Smarty to Twig: Loop Constructs Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates the conversion of Smarty's 'foreach' loop construct to Twig's 'for' loop. This example shows iterating over a list of products and accessing properties within the loop. ```smarty [{foreach $products as $product}]
  • [{$product->getName()}]
  • [{/foreach}] ``` ```twig {% for product in products %}
  • {{ product.getName() }}
  • {% endfor %} ``` -------------------------------- ### Custom Converter Implementation (PHP) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Illustrates how to create and register a custom converter class that extends `ConverterAbstract`. This allows for handling specific Smarty syntax not covered by the built-in converters. The example shows a simple replacement of a custom tag with a Twig equivalent and how to add it to the main converter instance. ```php registerBuiltInConverters(); $converter->addConverter(new CustomConverter()); // ... set up source converter and convert ``` -------------------------------- ### Convert Smarty section tag to Twig for loop Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Replaces the Smarty `section` tag, used for creating loops with start and end conditions, with the Twig `for` loop. It maps the `name`, `start`, and `loop` attributes to Twig's loop syntax. ```smarty [{section name=picRow start=1 loop=10}]foo[{/section}] ``` ```twig {% for picRow in 1..10 %}foo{% endfor %} ``` -------------------------------- ### Smarty to Twig: Conditional Statements Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows the transformation of Smarty's 'if', 'elseif', and 'else' conditional blocks into Twig's equivalent syntax. It includes examples with logical operators like AND. ```smarty [{if $user->isLoggedIn() && $cart->hasItems()}] Checkout available [{elseif $user->isLoggedIn()}] Add items to cart [{else}] Please login [{/if}] ``` ```twig {% if user.isLoggedIn() and cart.hasItems() %} Checkout available {% elseif user.isLoggedIn() %} Add items to cart {% else %} Please login {% endif %} ``` -------------------------------- ### Resolving Variable Scope Issues in Twig Loops Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Twig limits variable scope within blocks. Variables intended for use outside loops or blocks must be declared appropriately. The example shows how to access the last element of an array when the original Smarty code accessed a variable outside the loop. ```smarty [{foreach $myColors as $color}]
  • [{$color}]
  • [{/foreach}] [{$color}] ``` ```twig {% for color in myColors %}
  • {{ color }}
  • {% endfor %} {{ color }} ``` ```twig {% for color in myColors %}
  • {{ color }}
  • {% endfor %} {{ myColors|last }} ``` -------------------------------- ### Convert OXID oxinputhelp to Twig include with inputhelp parameters Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the conversion of the OXID `oxinputhelp` tag, used for displaying input help text, to Twig's `include` directive with specific parameters. This customizes the display of help information. ```smarty [{oxinputhelp ident="foo"}] ``` ```twig {% include "inputhelp.tpl" with {'sHelpId': getSHelpId(foo), 'sHelpText': getSHelpText(foo)} %} ``` -------------------------------- ### Use Configuration File (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command allows injecting PHP configuration code instead of using long command lines. It uses the --config-path parameter to specify the path to a configuration file that returns an instance of `toTwig\Config\ConfigInterface`. ```php php toTwig convert --config-path=config_file.php ``` -------------------------------- ### Convert Files in Directory (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Converts Smarty templates within a specified directory to Twig syntax using the command-line interface. This command initiates the conversion process for all .tpl files found in the given path. No external dependencies are required beyond the PHP executable and the converter tool itself. ```bash php toTwig convert --path=/path/to/templates ``` -------------------------------- ### Database Configuration (PHP) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Configures the Smarty to Twig conversion process for database sources using a PHP file. This allows programmatic control over database connections, specific columns to convert, and options like dry-run and diff output. The configuration is loaded via the `--config-path` CLI argument. ```php 'mysql://user:password@localhost/db_name' ]); $sourceConverter = new \toTwig\SourceConverter\DatabaseConverter($connection); $sourceConverter->setColumns([ 'oxactions.OXLONGDESC', 'oxcontents.OXCONTENT' ]); return \toTwig\Config\Config::create() ->setSourceConverter($sourceConverter) ->dryRun(false) ->diff(true); ``` ```bash php toTwig convert --config-path=config_database.php ``` -------------------------------- ### Convert Files/Directories (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command converts Smarty files to Twig syntax. It can operate on individual files or entire directories specified by the --path parameter. The --ext parameter allows specifying the output file extension. ```php php toTwig convert --path=/path/to/dir ``` ```php php toTwig convert --path=/path/to/file ``` ```php php toTwig convert --path=/path/to/dir --ext=.js.twig ``` -------------------------------- ### Convert Files with Custom Output Extension (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Converts Smarty templates in a directory and specifies a custom file extension for the output Twig files. This allows for better organization and integration with build processes. The `--ext` option controls the suffix added to converted files. ```bash php toTwig convert --path=/path/to/templates --ext=.twig ``` -------------------------------- ### Dry Run with Diff Output (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Performs a dry run of the Smarty to Twig conversion without modifying any files, instead showing the differences between the original and converted content. This is valuable for reviewing changes before applying them and understanding the impact of the conversion. The `--dry-run` and `--diff` flags enable this functionality. ```bash php toTwig convert --path=/path/to/templates --dry-run --diff ``` -------------------------------- ### Convert from Database (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command converts content from a database to Twig syntax. The --database parameter specifies the database connection string. The --database-columns parameter allows to specify which columns will be converted. The columns can be blacklisted using the minus sign. ```php php toTwig convert --database="mysql://user:password@localhost/db" ``` ```php php toTwig convert --database="..." --database-columns=oxactions.OXLONGDESC,oxcontents.OXCONTENT ``` ```php php toTwig convert --database="..." --database-columns=-oxactions.OXLONGDESC_1,-oxcontents.OXCONTENT_1 ``` -------------------------------- ### Convert Smarty Property Access to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Explains the differences in property access between Smarty and Twig. Manual fixes may be required, such as explicitly calling magic getters or using array-like syntax for properties without getters. ```smarty [{foreach from=$cattree->aList item=pcat}] [{pcat.val}] ``` ```twig {% for pcat in cattree.aList %} {{ pcat.val }} ``` ```twig {% for pcat in cattree.__get('aList') %} {{ pcat['val'] }} ``` -------------------------------- ### Convert Smarty Insert to Twig Include with Context Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts Smarty's insert tag, which often calls functions or methods to render dynamic content, to Twig's include directive with a context hash. This handles dynamic content inclusion with parameters. ```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()} %} ``` -------------------------------- ### Convert Single File (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Converts a single Smarty template file to Twig syntax via the command line. This is useful for targeted conversions or testing the tool on individual files. The tool reads the specified file and outputs the converted Twig content. ```bash php toTwig convert --path=/path/to/template.tpl ``` -------------------------------- ### Apply Specific Converters (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command specifies which converters to apply during the conversion process. The --converters parameter accepts a comma-separated list of converter names. Converters can be blacklisted using a minus sign. ```php php toTwig convert --path=/path/to/dir --ext=.html.twig --converters=for,if,misc ``` ```php php toTwig convert --path=/path/to/dir --ext=.html.twig --converters=-for,-if ``` -------------------------------- ### Convert Smarty Math to Twig Math Syntax Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the conversion of Smarty's math tag for performing calculations to Twig's native arithmetic expression syntax. This simplifies mathematical operations within templates. ```smarty [{math equation="x + y" x=1 y=2}] ``` ```twig {{ 1 + 2 }} ``` -------------------------------- ### Convert Smarty Miscellaneous Syntax to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Covers the conversion of miscellaneous Smarty syntax elements like literal delimiters and strip tags to their Twig equivalents. This includes handling special characters and whitespace. ```smarty [{ldelim}]foo[{ldelim}] ``` ```twig foo ``` ```smarty [{literal}]foo[{/literal}] ``` ```twig {# literal #}foo{# /literal #} ``` ```smarty [{strip}]foo[{/strip}] ``` ```twig {% spaceless %}foo{% endspaceless %} ``` -------------------------------- ### Dry Run Conversion (PHP) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md This command performs a dry run, displaying the proposed changes without modifying the files. It uses the --dry-run, --verbose, and --diff parameters to show the potential modifications. ```php php toTwig convert --path=/path/to/code --ext=.html.twig --dry-run ``` -------------------------------- ### Convert Smarty Variables to Twig Variables Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Details the conversion of various Smarty variable access syntaxes, including array access, object properties, and function calls, to their Twig equivalents. This covers basic variable output and property access. ```smarty [{$var}] ``` ```twig {{ var }} ``` ```smarty [{$contacts.fax}] ``` ```twig {{ contacts.fax }} ``` ```smarty [{$contacts[0]}] ``` ```twig {{ contacts[0] }} ``` ```smarty [{$contacts[2][0]}] ``` ```twig {{ contacts[2][0] }} ``` ```smarty [{$person->name}] ``` ```twig {{ person.name }} ``` ```smarty [{$oViewConf->getUrl($sUrl)}] ``` ```twig {{ oViewConf.getUrl(sUrl) }} ``` ```smarty [{($a && $b) | $c}] ``` ```twig {{ (a and b) or c }} ``` -------------------------------- ### Convert Database Columns (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Converts Smarty template syntax directly from database columns to Twig. This command requires a database connection string and optionally allows specifying which columns to convert or exclude. It's designed for large-scale migrations where templates are stored in the database. ```bash # Convert database columns with default settings php toTwig convert --database="mysql://user:password@localhost/db_name" # Convert specific database columns php toTwig convert --database="mysql://user:password@localhost/db_name" \ --database-columns=oxactions.OXLONGDESC,oxcontents.OXCONTENT # Exclude specific columns from conversion php toTwig convert --database="mysql://user:password@localhost/db_name" \ --database-columns=-oxactions.OXLONGDESC_1,-oxcontents.OXCONTENT_1 ``` -------------------------------- ### Convert OXID oxgetseourl to Twig seo_url Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates the OXID `oxgetseourl` tag, used for generating SEO-friendly URLs, to Twig's `seo_url` function. This ensures proper URL generation for OXID shops. ```smarty [{oxgetseourl ident=$oViewConf->getSelfLink()|cat:"cl=basket"}] ``` ```twig {{ seo_url({ ident: oViewConf.getSelfLink()|cat("cl=basket") }) }} ``` -------------------------------- ### Convert OXID oxeval to Twig include(template_from_string) Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts the OXID `oxeval` tag, which evaluates a variable as a template, to Twig's `include` function with `template_from_string`. This allows for dynamic template rendering based on string content. ```smarty [{oxeval var=$variable}] ``` ```twig {{ include(template_from_string(variable)) }} ``` -------------------------------- ### Smarty to Twig: Dynamic Includes Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates the conversion of the `oxid_include_dynamic` Smarty tag to Twig's `include_dynamic` function. This enables dynamic loading of template files. ```smarty [{oxid_include_dynamic file="form/formparams.tpl"}] ``` ```twig {% include_dynamic "form/formparams.tpl" %} ``` -------------------------------- ### Database Conversion with Custom Connection in PHP Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows how to perform database conversions using a custom Doctrine DBAL connection. This snippet configures a MySQL connection, specifies columns for conversion, registers converters, and then executes the conversion process, reporting the number of entries converted. Ideal for migrating content stored directly in the database. ```php 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'oxid_db', 'user' => 'root', 'password' => 'secret', 'charset' => 'utf8mb4' ]); $sourceConverter = new DatabaseConverter($connection); // Set specific columns to convert $sourceConverter->setColumns([ 'oxactions.OXLONGDESC', 'oxactions.OXLONGDESC_1', 'oxcontents.OXCONTENT', 'oxcontents.OXCONTENT_1' ]); $converter = new Converter(); $converter->registerBuiltInConverters(); $converter->setSourceConverter($sourceConverter); $results = $converter->convert($dryRun = false, $diff = false); echo "Converted " . count($results) . " database entries\n"; ``` -------------------------------- ### Convert Smarty Section Iteration to Twig Loop Index Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows how Smarty's `$smarty.section.arg` construct for loop iteration is converted to Twig's `loop.index0` or `loop.index`. Manual adjustment is needed as the converter does not handle these specific Smarty constructs. ```smarty [{if $review->getRating() >= $smarty.section.starRatings.iteration}] ``` ```twig {% if review.getRating() >= smarty.section.starRatings.iteration %} ``` ```twig {% if review.getRating() >= loop.index %} ``` -------------------------------- ### Convert Smarty Request Variable Access to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Details how Smarty's access to request variables (e.g., `$smarty.get.plain`) is converted to Twig using functions like `get_global_get`. Refactoring is recommended, and custom functions may be needed for other request variables. ```smarty [{if $smarty.get.plain == '1'}] popup[{/if}] ``` ```twig {% if smarty.get.plain == '1' %} popup{% endif %} ``` ```twig {% if get_global_get('plain') == '1' %} popup{% endif %} ``` -------------------------------- ### Convert Smarty Assign to Twig Set Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the direct conversion of Smarty's `assign` tag to Twig's `set` tag for variable assignment. This is a straightforward syntax replacement. ```smarty [{assign var="name" value="Bob"}] ``` ```twig {% set name = "Bob" %} ``` -------------------------------- ### Convert OXID oxid_include_widget to Twig include_widget Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the conversion of the OXID `oxid_include_widget` tag for including widget components to Twig's `include_widget` function. This is used for integrating reusable widget components. ```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 }) }} ``` -------------------------------- ### Convert Smarty Comments to Twig Comments Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the conversion of Smarty's comment syntax to Twig's comment syntax. Comments are used for notes within templates that are not rendered in the output. ```smarty [{* foo *}] ``` ```twig {# foo #} ``` -------------------------------- ### Smarty to Twig: Script and Style Management Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows the conversion of OXID's `oxscript` and `oxstyle` Smarty tags to Twig functions for managing script and style includes. This includes options for priority and dynamic loading. ```smarty [{oxscript include="js/pages/details.min.js" priority=10}] [{oxstyle include="css/libs/chosen/chosen.min.css"}] ``` ```twig {{ script({ include: "js/pages/details.min.js", priority: 10, dynamic: __oxid_include_dynamic }) }} {{ style({ include: "css/libs/chosen/chosen.min.css" }) }} ``` -------------------------------- ### Convert Smarty Include to Twig Include Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates Smarty's include tag for rendering other template files to Twig's include directive. This is used for template modularity and reusability. ```smarty [{include file='page_header.tpl'}] ``` ```twig {% include 'page_header.tpl' %} ``` -------------------------------- ### Convert oxstyle Smarty tag to Twig style function Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Handles the conversion of the Smarty `oxstyle` tag, used for including CSS files, to the Twig `style` function. The `include` parameter specifies the CSS file path. This conversion simplifies the process of adding stylesheets. ```smarty [{oxstyle include="css/libs/chosen/chosen.min.css"}] ``` ```twig {{ style({ include: "css/libs/chosen/chosen.min.css" }) }} ``` -------------------------------- ### Convert Smarty Variable Set with Comparison to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Illustrates the conversion of Smarty's variable assignment and conditional logic, especially when checking for set or unset properties. Twig's `is same as` comparison is often required for precise checks, particularly with null properties. ```smarty [{if $_sSelectionHashCollection}] [{assign var="_sSelectionHashCollection" value=$_sSelectionHashCollection|cat:","}] [{/if}] ``` ```twig {% if _sSelectionHashCollection %} {% set _sSelectionHashCollection = _sSelectionHashCollection|cat(",") %} {% endif %} ``` ```twig {% if _sSelectionHashCollection is not same as("") %} {% set _sSelectionHashCollection = _sSelectionHashCollection|cat(",") %} {% endif %} ``` -------------------------------- ### Convert OXID oxcontent to Twig include_content Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates the OXID-specific `oxcontent` tag, used for including content based on an identifier, to Twig's `include_content` function. This is for dynamic content loading within OXID templates. ```smarty [{oxcontent ident='oxregisteremail'}] ``` ```twig {% include_content 'oxregisteremail' %} ``` -------------------------------- ### Smarty to Twig: Variable Assignment Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Illustrates the conversion of Smarty's variable assignment syntax to Twig's 'set' directive. This covers both static value assignments and dynamic assignments using method calls on objects. ```smarty [{assign var="name" value="Bob"}] [{assign var="price" value=$product->getPrice()}] ``` ```twig {% set name = "Bob" %} {% set price = product.getPrice() %} ``` -------------------------------- ### Smarty to Twig: Block Inheritance Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows the conversion of Smarty's block definition syntax to Twig's 'block' and 'endblock' syntax. This is fundamental for template inheritance patterns. ```smarty [{block name="content"}] Default content [{/block}] ``` ```twig {% block content %} Default content {% endblock %} ``` -------------------------------- ### Convert Smarty Logic Operators to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Addresses the conversion of Smarty's `||` and `&&` operators to Twig's `or` and `and`. The converter may not handle these if not space-separated, necessitating manual changes. ```smarty [{if $product->isNotBuyable()||($aVariantSelections&&$aVariantSelections.selections)||$product->hasMdVariants()}] ``` ```twig {% if product.isNotBuyable()||(aVariantSelections&&$aVariantSelections.selections) or product.hasMdVariants() %} ``` ```twig {% if product.isNotBuyable() or (aVariantSelections and aVariantSelections.selections) or product.hasMdVariants() %} ``` -------------------------------- ### Convert OXID oxid_include_dynamic to Twig include_dynamic Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates the OXID-specific `oxid_include_dynamic` tag for dynamically including templates to Twig's `include_dynamic` directive. This is used for including templates based on runtime conditions. ```smarty [{oxid_include_dynamic file="form/formparams.tpl"}] ``` ```twig {% include_dynamic "form/formparams.tpl" %} ``` -------------------------------- ### Convert Smarty If to Twig If Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Shows the conversion of Smarty's conditional if statements, including logical operators and function calls, to Twig's equivalent if syntax. This handles complex conditional logic. ```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 %} ``` -------------------------------- ### Convert Smarty Capture to Twig Set Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates Smarty's capture mechanism, used for capturing output into a variable, to Twig's set directive. This allows for storing and reusing template fragments. ```smarty [{capture name="foo" append="var"}] bar [{/capture}] ``` ```twig {% set foo %}{{ var }} bar {% endset %} ``` -------------------------------- ### Smarty to Twig: SEO URL Generation Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates the conversion of the `oxgetseourl` Smarty tag to a Twig function for generating SEO-friendly URLs. This is crucial for improving search engine visibility. ```smarty [{oxgetseourl ident=$oViewConf->getSelfLink()|cat:"cl=basket"}] ``` ```twig {{ seo_url({ ident: oViewConf.getSelfLink()|cat("cl=basket") }) }} ``` -------------------------------- ### Map Smarty filters to Twig filters for text manipulation Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Provides a direct mapping for various Smarty text manipulation filters to their equivalent Twig filters. This includes functions for word wrapping, date formatting, parameter addition, string escaping, file size formatting, time formatting, language translation, and truncation. ```smarty smartwordwrap ``` ```twig smart_wordwrap ``` ```smarty date_format ``` ```twig date_format ``` ```smarty oxaddparams ``` ```twig add_url_parameters ``` ```smarty oxaddslashes ``` ```twig addslashes ``` ```smarty oxenclose ``` ```twig enclose ``` ```smarty oxfilesize ``` ```twig file_size ``` ```smarty oxformattime ``` ```twig format_time ``` ```smarty oxformdate ``` ```twig format_date ``` ```smarty oxmultilangassign ``` ```twig translate ``` ```smarty oxmultilangsal ``` ```twig translate_salutation ``` ```smarty oxnubmerformat ``` ```twig format_currency ``` ```smarty oxtruncate ``` ```twig truncate ``` ```smarty oxwordwrap ``` ```twig wordwrap ``` -------------------------------- ### Smarty to Twig: Widget Inclusion Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows the conversion of the `oxid_include_widget` Smarty tag to Twig's `include_widget` function. This allows for the dynamic inclusion of various OXID widgets within templates. ```smarty [{oxid_include_widget cl="oxwCategoryTree" cnid=$oView->getCategoryId() deepLevel=0}] ``` ```twig {{ include_widget({ cl: "oxwCategoryTree", cnid: oView.getCategoryId(), deepLevel: 0 }) }} ``` -------------------------------- ### Convert oxprice Smarty tag to Twig format_price function Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts the Smarty `oxprice` tag, used for formatting prices with currency, to the Twig `format_price` function. It takes the price value and currency as arguments. The Twig version uses named arguments for clarity. ```smarty [{oxprice price=$basketitem->getUnitPrice() currency=$currency}] ``` ```twig {{ format_price(basketitem.getUnitPrice(), { currency: currency }) }} ``` -------------------------------- ### Filter Converters (CLI) Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Allows selective application of conversion rules during the Smarty to Twig process. You can specify which converters to use or exclude specific ones using the `--converters` option. This is useful for advanced control over the conversion process or when dealing with specific Smarty constructs. ```bash # Use only specific converters php toTwig convert --path=/path/to/templates --converters=for,if,variable # Exclude specific converters php toTwig convert --path=/path/to/templates --converters=-block,-capture ``` -------------------------------- ### Smarty to Twig: Template Inclusion Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Illustrates the conversion of Smarty's 'include' tag, which allows embedding one template into another, to Twig's 'include' directive. It shows passing parameters to the included template. ```smarty [{include file='header.tpl' title="Welcome"}] ``` ```twig {% include 'header.tpl' with {'title': 'Welcome'} %} ``` -------------------------------- ### Convert Smarty Block to Twig Block Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts Smarty's block syntax for defining content sections to Twig's equivalent block syntax. This is useful for organizing and overriding content within templates. ```smarty [{block name="title"}]Default Title[{/block}] ``` ```twig {% block title %}Default Title{% endblock %} ``` -------------------------------- ### Convert Smarty Cycle to Twig Smarty Cycle Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Illustrates the conversion of Smarty's cycle tag, which iterates through a list of values, to a Twig function. This is useful for alternating styles or values in loops. ```smarty [{cycle values="val1,val2,val3"}] ``` ```twig {{ smarty_cycle(["val1", "val2", "val3"]) }} ``` -------------------------------- ### Convert Smarty Global Variable Access to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Illustrates the conversion of accessing global variables in Smarty (e.g., `smarty.capture.loginErrors`) to Twig. The converter replaces 'smarty' with 'twig' for global variable access, but manual verification might be needed. ```smarty [{$smarty.capture.loginErrors}] ``` ```twig {{ smarty.capture.loginErrors }} ``` ```twig {{ twig.capture.loginErrors }} ``` -------------------------------- ### Convert oxscript Smarty tag to Twig script function Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Transforms the Smarty `oxscript` tag, used for including JavaScript files, into the Twig `script` function. It supports parameters like `include`, `priority`, and `dynamic`. The `__oxid_include_dynamic` variable is passed automatically in Twig. ```smarty [{oxscript include="js/pages/details.min.js" priority=10}] ``` ```twig {{ script({ include: "js/pages/details.min.js", priority: 10, dynamic: __oxid_include_dynamic }) }} ``` -------------------------------- ### Convert Smarty Image URL to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Demonstrates the conversion of Smarty's `getImageUrl` function call to its Twig equivalent. The converter may not remove the '$' sign from variable names, requiring manual fixing. ```smarty [{$oViewConf->getImageUrl($sEmailLogo, false)}] ``` ```twig {{ oViewConf.getImageUrl($sEmailLogo, false) }} ``` ```twig {{ oViewConf.getImageUrl(sEmailLogo, false) }} ``` -------------------------------- ### Convert OXID oxifcontent to Twig ifcontent block Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates the OXID `oxifcontent` tag, used for conditional rendering based on content availability, to Twig's `ifcontent` block. This allows for conditional display of content elements. ```smarty [{oxifcontent ident="TOBASKET" object="aObject"}]foo[{/oxifcontent}] ``` ```twig {% ifcontent ident "TOBASKET" set aObject %}foo{% endifcontent %} ``` -------------------------------- ### Filter Converters Programmatically in PHP Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates how to programmatically filter which converters are used by the toTwig converter instance. This allows for selective application of conversions, either by including specific converters or excluding others. Useful for targeted migrations or incremental updates. ```php registerBuiltInConverters(); // Only use specific converters $converter->filterConverters(['for', 'if', 'variable']); // Or exclude specific converters $converter->filterConverters(['-block', '-capture']); // Get list of active converters foreach ($converter->getConverters() as $conv) { echo $conv->getName() . ": " . $conv->getDescription() . "\n"; } ``` -------------------------------- ### Smarty to Twig: Price Formatting Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Shows the conversion of the OXID `oxprice` Smarty tag to a Twig function for formatting prices, including currency. This ensures prices are displayed correctly according to locale and currency settings. ```smarty [{oxprice price=$product->getPrice() currency=$currency}] ``` ```twig {{ format_price(product.getPrice(), { currency: currency }) }} ``` -------------------------------- ### Convert Smarty Counter to Twig Set for Counter Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Demonstrates the conversion of Smarty's counter tag, used for incrementing a counter, to Twig's set directive. This allows for maintaining and updating counter values in templates. ```smarty [{counter}] ``` ```twig {% set defaultCounter = ( defaultCounter|default(0) ) + 1 %} ``` -------------------------------- ### Convert Smarty Mailto to Twig Mailto Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates Smarty's mailto tag for creating email links to Twig's equivalent syntax. This is a straightforward conversion for generating email links. ```smarty [{mailto address='me@example.com'}] ``` ```twig {{ mailto('me@example.com') }} ``` -------------------------------- ### Adapting Smarty Section Loops to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Smarty's `section` tag with `loop` can behave differently based on whether `loop` is an array or integer. Twig's `for` loop requires explicit definition of the iteration range or collection. ```smarty [{section name="month" start=1 loop=13}] [{$smarty.section.month.index}] [{/section}] [{section name=customer loop=$custid}] id: [{$custid[customer]}]
    [{/section}] ``` ```twig {% for month in 1..13 %} {{ loop.index0 }} {% endfor %} {% for customer in 0..$custid %} id: {{ custid[customer] }}
    {% endfor %} ``` ```twig {% for month in 1..12 %} {{ loop.index0 }} {% endfor %} {% for customer in custid %} id: {{ customer }}
    {% endfor %} ``` -------------------------------- ### Convert OXID oxhasrights to Twig hasrights block Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts the OXID `oxhasrights` tag, used for conditional rendering based on user permissions, to Twig's `hasrights` block. This controls access to specific template sections. ```smarty [{oxhasrights object=$edit readonly=$readonly}]foo[{/oxhasrights}] ``` ```twig {% hasrights { "object": "edit", "readonly": "readonly", } %}foo{% endhasrights %} ``` -------------------------------- ### Convert Smarty Foreach to Twig For Loop Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates Smarty's foreach loop structure to Twig's for loop syntax. This is a fundamental conversion for iterating over arrays and objects. ```smarty [{foreach $myColors as $color}]foo[{/foreach}] ``` ```twig {% for color in myColors %}foo{% endfor %} ``` -------------------------------- ### Translating Smarty Array Access to Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Smarty's `$myArray.$itemIndex` syntax for accessing array elements needs to be converted to Twig's `myArray[itemIndex]` format. ```smarty [{$myArray.$itemIndex}] ``` ```twig {{ myArray.$itemIndex }} ``` ```twig {{ myArray[itemIndex] }} ``` -------------------------------- ### Handling Redeclared Blocks in Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Twig prohibits redeclaring blocks with the same name. Ensure each block has a unique identifier. The fix involves appending suffixes like `_A` and `_B` to distinguish them. ```smarty [{block name="foo"}] ... [{/block}] [{block name="foo"}] ... [{/block}] ``` ```twig {% block foo %} ... {% endblock %} {% block foo %} ... {% endblock %} ``` ```twig {% block foo_A %} ... {% endblock %} {% block foo_B %} ... {% endblock %} ``` -------------------------------- ### Convert OXID oxmailto to Twig mailto Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Translates the OXID-specific `oxmailto` tag, similar to the standard mailto tag, to Twig's `mailto` function. This handles the generation of email links within OXID templates. ```smarty [{oxmailto address='me@example.com'}] ``` ```twig {{ mailto('me@example.com') }} ``` -------------------------------- ### Smarty to Twig: Content Block Inclusion Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Illustrates the conversion of the `oxcontent` Smarty tag to Twig's `include_content` function. This is used for embedding content from CMS blocks into templates. ```smarty [{oxcontent ident='oxregisteremail'}] ``` ```twig {% include_content 'oxregisteremail' %} ``` -------------------------------- ### Smarty to Twig: Multilanguage Support Conversion Source: https://context7.com/oxid-esales/smarty-to-twig-converter/llms.txt Demonstrates the conversion of OXID eShop's `oxmultilang` Smarty tag to Twig's `translate` function. This handles internationalization by looking up language identifiers. ```smarty [{oxmultilang ident="ERROR_404"}] [{oxmultilang ident="WELCOME_MESSAGE" suffix="SHOP"}] ``` ```twig {{ translate({ ident: "ERROR_404" }) }} {{ translate({ ident: "WELCOME_MESSAGE", suffix: "SHOP" }) }} ``` -------------------------------- ### Correcting Regex Replace in Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Complex regular expression replacements in Smarty may not convert correctly. Manual correction is recommended to ensure proper functionality, especially with the `regex_replace` filter. ```smarty [{birthDate|regex_replace:"/^([0-9]{4})[-]/":""|regex_replace:"/[-]([0-9]{1,2})$/":""}] ``` ```twig {{ birthDate|regex_replace("/^([0-9]{4)})[-]/":"")|regex_replace("/[-]([0-9]{1, 2})$/":"") }} ``` ```twig {{ birthDate|regex_replace("/^([0-9]{4})[-]/","" )|regex_replace("/[-]([0-9]{1,2})$/","" ) }} ``` -------------------------------- ### Convert OXID oxmultilang to Twig translate Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Converts the OXID `oxmultilang` tag, used for internationalization and translation, to Twig's `translate` function. This is crucial for multilingual support in templates. ```smarty [{oxmultilang ident="ERROR_404"}] ``` ```twig {{ translate({ ident: "ERROR_404" }) }} ``` -------------------------------- ### String Concatenation in Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md Twig does not support direct string concatenation with variables inside strings like Smarty. Use the `~` operator for string concatenation in Twig. The converter might struggle with complex string assignments involving variables. ```smarty [{assign var="sUrl" value="http://www.example.com?aid=`$sAccountId`&wid=`$sWidgetId`&csize=20&start=0"}] [{assign var="divId" value=oxStateDiv_$stateSelectName}] ``` ```twig {% set sUrl = "http://www.example.com?aid=`$sAccountId`&wid=`$sWidgetId`&csize=20&start=0" %} {% set divId = oxStateDiv_$stateSelectName %} ``` ```twig {% set sUrl = "http://www.example.com?aid=" ~ sAccountId ~ "&wid=" ~ sWidgetId ~ "&csize=20&start=0" %} {% set divId = "oxStateDiv_" ~ stateSelectName %} ``` -------------------------------- ### Fixing Escaped Variables in Twig Source: https://github.com/oxid-esales/smarty-to-twig-converter/blob/master/README.md In Twig, variables are escaped by default. Use the `|raw` filter for variables containing HTML or unsafe characters. Alternatively, `template_from_string` can be used for template variables. ```smarty [{$product->oxarticles__oxtitle->value}] ``` ```twig {{ product.oxarticles__oxtitle.value }} ``` ```twig {{ product.oxarticles__oxtitle.value|raw }} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.