Skip to content

Twig Functions Reference

Twig Functions Reference ​

In Shopware, Twig functionality is extended with custom tags, functions, filters, extensions, and additional syntax.

INFO

Official support for complete Twig multi inheritance using sw_* equivalents available since 6.7

WARNING

Templates which are imported via {% sw_use %} are not allowed to have additional twig statements outside of twig blocks. Therefore, changes in core templates which are imported via {% sw_use %} might break your app or plugin.

Tags ​

FunctionDescriptionNotes
sw_extendsInherits from another file with support for multi inheritance. The API is the same like in Twig's default extendsSee Twig 3 documentation for extends
sw_includeIncludes template partials with support for multi inheritance. The API is the same like in Twig's default include but limited to one file at onceSee Twig 3 documentation for include
sw_embedIncludes another file with directly overwriting blocks with support for multi inheritance. The API is the same like in Twig's default embedSee Twig 3 documentation for embed
sw_useIncludes template blocks without rendering them from another file with support for multi inheritance. The API is the same like in Twig's default useSee Twig 3 documentation for use
sw_importIncludes all macros from another file with support for multi inheritance. The API is the same like in Twig's default importSee Twig 3 documentation for import
sw_fromIncludes single macros from another file with support for multi inheritance. The API is the same like in Twig's default fromSee Twig 3 documentation for from
sw_iconDisplays an icon from a given icon setSee Add custom icon guide for details.
sw_thumbnailsRenders a tag with correctly configured “srcset” and “sizes” attributes based on the provided parametersSee Add thumbnail guide for more information.

Functions ​

FunctionDescriptionNotes
configGets a value from the system config (used by plugins and global settings) for the given sales channelSee Reading the configuration values
theme_configGets a value from the current themeSee Theme configuration
sw_blockRenders a block of the same or another file with support for multi-inheritance. This is the same as in Twig's default blockSee Twig 3 documentation for block
sw_sourcePrints the content of a template file with support for multi-inheritance. This is the same as in Twig's default sourceSee Twig 3 documentation for source
sw_includeRenders the content of another template file with support for multi-inheritance. This is the same as in Twig's default include and the new sw_include tagSee Twig 3 documentation for include
arrayWraps an array in an ArrayFacade---
version_compareCompares two version strings---

Filter ​

FilterDescriptionNotes
replace_recursiveEnables recursive replacement in addition to twig's default replace filterTo see an example, see the guide on add custom JavaScript
currencyAdopts currency formatting: The currency symbol and the comma setting.---
intvalCasts a scalar or stringable value to an integer---
floatvalCasts a scalar or stringable value to a float---
strvalCasts a scalar or stringable value to a string---
boolvalCasts a scalar or stringable value to a boolean---
json_encodeEncodes values as JSON while preserving zero fractions and respecting entity field visibility---
md5Hashes a string or array with MD5---
sha256Hashes a string or array with SHA-256---
sw_sanitizeFilters tags and attributes from a given string. By default, Twig's auto escaping is on, so this filter explicitly allows basic HTML tags like <i%gt;, <b>,...---
sw_convert_unitConvert between measurement unitsAvailable since 6.7.1.0, to see examples, see the adr on the measurement system

Extensions ​

ExtensionDescriptionNotes
sw_breadcrumb_full()Returns all categories defined in the breadcrumb as an arrayContains functionalities of sw_breadcrumb_types and sw_breadcrumb_build_types
sw_breadcrumb()Returns the category tree as array. Entry points of the SalesChannel ( e.g. footer, navigation) are filtered out.Deprecated in 6.5.0
sw_breadcrumb_types()Yields the types of the categories within the breadcrumbDeprecated in 6.5.0
sw_breadcrumb_build_types()returns the same as sw_breadcrumb_types, only without another repository callDeprecated in 6.5.0
seoUrl()Returns seo URL of given route---
searchMedia()Resolves media ids to media objectsSee Add media guide for details.
rawUrl()Returns full URL---

PHP-like syntax ​

TypeSyntax
Control flowforeach, break, continue, and return
Operators===, !==, &&, and ||
Type tests{% if value is <type> %} with true, false, array, bool, boolean, callable, float, int, integer, instanceof, object, scalar, and string
Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)