Resources/scripts
directory of your app. For each hook you want to execute a script on, create a new subdirectory. The name of the subdirectory needs to match the name of the hook..twig
files inside each of these subdirectories, that will be executed when the hook gets triggered.include
folder and then import them using the twig import functionality.return
keyword to return values to the caller.store-api-hook
defines a cache_key
and a response
function. Those functions are closely related, but are executed separately. To implement the different functions, you use different twig blocks with the name of the function:cache_key
function is optional. That means you can omit that block in your script without an error (but caching for the endpoint won't work in that case). The response
function is required, which means that if your script does not provide a response
block it will lead to an error.cache_key
block you don't necessarily have access to the same data and services as in the response
block. The available data and services are described for each hook (or each function in InterfaceHooks) in the reference documentation.|trans
-filter.===
!==
not equals operator as well.foreach
for...in
syntax for loops you can also use a foreach
tag.is
is
check to check the type of a variable.true
false
boolean
/ bool
string
scalar
object
integer
/ int
float
callable
array
intval
intval
filter.intval
strval
boolval
floatval
&&
and ||
AND
or OR
in if-conditions, you can use the &&
or ||
shorthands.return
tagreturn
tag to return values from inside macros.ServiceStubs
-class, that can be used as typehint in your script, so you get auto-completion features of your IDE.product-page-loaded
-hook, that loads the media entity by id and adds it to the page object, so the data is available in templates.APP_ENV = dev
, please ensure you set the correct env - e.g. in your .env
file - when developing app scripts .script
icon.debug.dump()
function inside your scripts to dump data to the debug view. A script like this: