ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

set-block

Summary

Redirects the output from a block of template code to a string.

Usage

{set-block variable=$variable [ name=name ] [ scope=scope ]}
...
{/set-block}

Parameters

NameTypeDescriptionRequired
variable string The name of the variable (with dollar sign). Yes.
name string The name of the target namespace. No.
scope string The scope ("global", "root" or "relative"). No.

Description

This mechanism will silently process all template code which is encapsulated by "{set-block ...}" and "{/set-block}". It will not produce any actual output. Instead, the generated output will be assigned to a variable specified by the "variable" parameter (as a string). If the variable does not exist, it will be automatically created. If the same target variable is used in several blocks, its contents will be overwritten every time a new block is processed.

Examples

Example 1

{set-block variable=$example}
    {def $test=array( 'x', 'y', 'z' )}
    Hello world - {$test[1]}
{/set-block}
...
{$example}

The code which is encapsulated by "set-block" will not produce any output. Instead, the output will be put into a string called $example. When this variable is accessed directly, the following output will be produced: "Hello world - y".

Example 2

{set-block scope=global variable=cache_ttl}0{/set-block}

This will put zero into the "cache_ttl" global variable and thus disable view caching for this page.

Balazs Halasy (06/02/2004 1:23 pm)

Svitlana Shatokhina (08/10/2008 9:43 am)

Balazs Halasy, Svitlana Shatokhina


Comments

  • include doesn't work insade set-block

    include doesn't work insade set-block
  • Using set block within in information collection templates

    /content/collectedinfomail/form.tpl will acces the following variables:

    {set-block scope=root variable=email_receiver}test@test.com{/set-block}
    {set-block scope=root variable=subject}Subject{/set-block}
    {set-block scope=root variable=email_sender}noreply@test.com{/set-block}
    {set-block scope=root variable=redirect_to_node_id}2{/set-block}

    Notice: The sender and receiver mailadress have to be different, otherwise receiver variable will not be set!

  • View cache example should use scope=global

    Since scope isn't that used anymore (since the template language changed in 3.6), the example should use scope=global to avoid people having troubles with it when the try to use it in a included template.

    So:
    {set-block scope=global variable=cache_ttl}0{/set-block}