spryker / cms-block
CmsBlock module
Requires
- php: >=8.3
- spryker/acl-merchant-portal-extension: ^1.0.0
- spryker/cms-block-extension: ^1.0.0
- spryker/event: ^2.0.0
- spryker/glossary: ^3.1.0
- spryker/kernel: ^3.86.0
- spryker/locale: ^3.0.0 || ^4.0.0
- spryker/propel-orm: ^1.0.0
- spryker/store: ^1.0.0
- spryker/symfony: ^3.0.0
- spryker/touch: ^3.0.0 || ^4.0.0
- spryker/transfer: ^3.27.0
- spryker/twig: ^3.36.0
- spryker/twig-extension: ^1.0.0
Requires (Dev)
Provides
None
Conflicts
- spryker/configuration: <1.11.0
Replaces
None
- 3.12.0
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.0
- 3.8.0
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- dev-master / 3.0.x-dev
- 3.0.2
- 3.0.1
- 3.0.0
- 2.3.0
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-hotfix/testing-propel
- dev-beta/spryker-mini-api-framework
- dev-beta/glue-backend-prototype-v4
- dev-beta/te-9873-backend-glue-application-plagin-context
This package is auto-updated.
Last update: 2026-12-01 08:59:18 UTC
README
CmsBlock supports management of blocks. Blocks can be viewed as fully localizable partial content snippets that can be embedded in other pages such as Product pages, Category pages, and so on. The CMS Block module supports flexible extension by adding a new connector.
Installation
composer require spryker/cms-block
Rendering placeholder content in a Twig sandbox
The renderCmsBlockAsTwig Twig function, used to embed CMS blocks in e-mails, renders each placeholder of a block as a Twig template. Placeholder content is written in the Back Office. By default it is rendered by the Zed application Twig environment, so it can call every Twig function and filter registered there and read the app global, which holds the application container.
To render placeholder content in a Twig sandbox, override CmsBlockConfig::isPlaceholderTwigSandboxEnabled() at project level:
namespace Pyz\Zed\CmsBlock; use Spryker\Zed\CmsBlock\CmsBlockConfig as SprykerCmsBlockConfig; class CmsBlockConfig extends SprykerCmsBlockConfig { public function isPlaceholderTwigSandboxEnabled(): bool { return true; } }
With the override in place:
- Placeholder content can use the Twig core tags and the filters, functions and tests of the Zed Twig environment, except the ones that
getTwigSandboxRestrictedTags(),getTwigSandboxRestrictedFilters(),getTwigSandboxRestrictedFunctions()andgetTwigSandboxRestrictedTests()return. Tags that Twig extensions of the application add are not available. - An output expression that uses a restricted filter, function, test or method, or passes a callable that is not an arrow function to a filter such as
map, rendersACCESS RESTRICTEDinstead, and the rest of the content is rendered:Hello {{ constant('PHP_VERSION') }}rendersHello ACCESS RESTRICTED. A restricted name that no Zed extension provides, such as a chart function of a module that is not installed, is restricted as well. A restricted tag, or a restricted call outside of an output expression, such as in asetoriftag or in a block rendered byblock(), rendersACCESS RESTRICTEDinstead of the whole placeholder content. Each restriction is logged as a warning. In debug mode of the Zed Twig environment,ApplicationConstants::ENABLE_APPLICATION_DEBUGby default, a restriction throws aTwig\Sandbox\SecurityErrorinstead, so the e-mail fails to render and the error names the restricted call. - By default, the restricted tags are
include,embed,extends,import,fromanduse, the restricted filter isserialize, and the restricted functions areinclude_only,template_from_string,constant,enum,enum_cases,attribute,getenv,dump,fragment_uri,render,render_*,controller,chart,barChart,pieChartandlineChart, and the restricted test isconstant. A*matches any characters, so a name ending with*restricts every name with that prefix. A function that needs the Twig environment or context gets the application environment, soinclude_onlyand the chart functions, which render templates or Back Office statistics, are restricted. - Methods can only be called on objects of the classes that
getTwigSandboxAllowedMethodClasses()returns, by default transfer objects. Every public method is allowed, such as{{ mail.customer.firstName }}or{{ mail.order.toArray() }}, except the ones whose name starts with a prefix ofgetTwigSandboxRestrictedMethodPrefixes(): by default the writers, such assetName()andfromArray(), so placeholder content cannot change data. include()andsource()load only templates whose extensiongetTwigSandboxAllowedTemplateExtensions()returns, by defaulttwigandhtml, and whose name does not start with/or contain.., a backslash or a control character, such as{{ include('@MyModule/mail/snippet.twig') }}. The included template is rendered in the sandbox as well, so it cannot use a restricted tag, such asextends,embedorinclude, and a restriction in it rendersACCESS RESTRICTEDin place of theinclude()expression. Any other name rendersACCESS RESTRICTED.configurationValue()andconfigurationValues()read the settings that the configuration schema does not mark assecret. In Zed they would return the decrypted value of a secret setting, soconfigurationValue()of a secret setting rendersACCESS RESTRICTED, andconfigurationValues()leaves secret settings out. This holds for a key given by position, by name, spread from a mapping or captured by asettag. A key that is not a string rendersACCESS RESTRICTED. Only the keys that the content reads are looked up, withConfigurationFacade::getConfigurationSettingCollection(), by the key thatconfigurationValue()resolves, thestatic_keyof a setting included. Without the optionalspryker/configurationmodule, there are no secret settings. CmsBlock conflicts withspryker/configurationversions before 1.11.0, which do not have this method.render()andcontroller()are restricted by default: a sub-request skips the Back Office firewall and access control, so placeholder content could read and change Back Office data, for example{{ render('/customer/index/table') }}in an e-mail to its editor. A project that removesrenderandcontrollerfromgetTwigSandboxRestrictedFunctions()accepts this, as the Spryker Suite does insrc/Pyz/CmsBlock/src/Pyz/Zed/CmsBlock/CmsBlockConfig.php, andrender()then only renders a relative URL, such as{{ render('/user/index') }}or{{ render('/') }}, or a controller action reference made of/-separated names of letters, digits and hyphens, with the inline strategy, without path segments that start with_, without a script name such asindex.php, and without query parameters starting with_, HTML entities such as&_path=included. It renders at most three nested fragments. Any other fragment rendersACCESS RESTRICTED. An e-mail sent without a current request, for example by the OMS, cannot render a fragment:ignore_errors: truedoes not help there, as on a project without the sandbox.- Filters such as
map,filter,reduceandsort, and thehas someandhas everyoperators, only accept arrow functions, not PHP function names. - The
appglobal is not available.
The sandbox needs Twig 3.29 or later and throws a TwigSandboxNotSupportedException on earlier versions. The method returns false by default, so a project keeps the previous behavior until it adds the override. The Spryker Suite ships the override in src/Pyz/CmsBlock/src/Pyz/Zed/CmsBlock/CmsBlockConfig.php. When you add a Twig function or filter to Zed that reads configuration, secrets or files, or that renders other templates or pages, add it to the restricted lists. Never remove the default restricted names, except render and controller as described above.