Skip to content

Shopware's twig functions

Shopware's twig functions

In Shopware, we extend Twig's functionality by custom ones. See our own actions below.

Functions

FunctionDescriptionNotes
sw_extendsInherits from another file with support for multi inheritance. The API is the same like in twigs default extends---
sw_includeIncludes template partials with support for multi inheritance. The API is the same like in twigs default include---
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.
sw_csrfGenerates a valid CSRF token and inject it as a hidden input field to the formMore details in CSRF protection guide.
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

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.---
sw_sanitizeFilters tags and attributes from a given string.---

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---