Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Swark operators: request and system

The request and system operators of the swark extension - charset, current_siteaccess, current_layout, is_post_request, server, cookie, user_id_by_login, variable_names, debug, debug_attributes, redirect, return and…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/template-operators/swark-operators-request-and-system.md

On this page

Swark operators: request and system

These swark operators read the request and the system, write to the debug output, or end the request. The classes are in extension/swark/autoloads/classes/; see The swark operators for how they are registered.

Contents

  1. Reading: charset, current_siteaccess, current_layout, is_post_request, server, cookie, user_id_by_login, variable_names
  2. Debug output: debug, debug_attributes
  3. Operators with side effects: redirect, return, clear_object_cache

Reading

charset

No parameters, no input. Returns the HTTP charset (eZTextCodec::httpCharset()).

current_siteaccess

No parameters. Returns the name of the current siteaccess ($GLOBALS['eZCurrentAccess']['name']).

current_layout

No parameters. Returns the layout key of the design resource (set by the layout/set view), or false. Empty on an ordinary page.

is_post_request

No parameters. true when $_SERVER['REQUEST_METHOD'] is POST.

server

ParameterRequired
variable_nameyes

Returns $_SERVER[<name in upper case>], or false with a debug warning when it is not set. The value is raw: wash it, and never print server variables on a public page.

ParameterRequired
nameyes

Reads $_COOKIE[name], or false with a debug warning. It does not set cookies. The value comes from the visitor: wash it. Not shown in the example because the command line has no cookies.

user_id_by_login

ParameterRequired
loginyes

Returns the content object id of the user with that login (escaped SQL on ezuser), or false. When login is empty the input is used, but because the parameter is required the piped form logs "Parameter 'login' missing" warnings: call it as a function.

variable_names

ParameterRequiredDefault
in_debugno1

Lists the names of the template variables of every namespace ($name or $namespace:name). With the default the list goes to the debug output as a notice; with 0 it is returned.

{def $title = 'x' $count = 3}
1 charset: {charset()}
2 current_siteaccess: {current_siteaccess()}
3 current_layout: [{current_layout()}]
4 is_post_request: {is_post_request()|choose( 'no', 'yes' )}
5 server SCRIPT_NAME: {server( 'script_name' )}
6 user_id_by_login: admin={user_id_by_login( 'admin' )}, anonymous={user_id_by_login( 'anonymous' )}, nobody={user_id_by_login( 'nobody-here' )|get_type}
7 variable_names: {variable_names( 0 )}

Output:

1 charset: utf-8
2 current_siteaccess: site
3 current_layout: []
4 is_post_request: no
5 server SCRIPT_NAME: bin/php/ezexec.php
6 user_id_by_login: admin=14, anonymous=10, nobody=boolean[false]
7 variable_names: $title, $count

Debug output

debug

ParameterRequiredDefault
headernoDebug operator

Writes the input to the debug output as a notice (eZDebug::writeNotice()) and returns nothing.

debug_attributes

ParameterRequiredDefault
headernoDebug attributes operator
depthno2

Writes the attribute tree of the input, like the kernel's attribute operator, to the debug output. An integer first parameter is taken as the depth.

Neither is shown in a rendered example: their output goes only to the debug output (shown when debug output is enabled for the request), not into the page.

Operators with side effects

Not run on a development installation: these operators stop the request, send headers or empty caches, which a read-only example must not do. Their behavior is described from the code.

redirect

ParameterRequiredDefault
urlyes
statusno302

Redirects with eZHTTPTool::redirect() and ends the request with eZExecution::cleanExit(). A URL without a scheme is prefixed with the index directory. When url is null the input is used.

{redirect( '/content/view/full/89', 301 )}

return

ParameterRequiredDefault
content_typenoempty

Sends the input as the whole response: sets Content-Type (when given) and Content-Length, discards all output buffers, prints the input and ends the request. Used to answer small JSON or text requests from a template.

{json_encode( hash( 'ok', true() ) )|return( 'application/json' )}

clear_object_cache

No parameters. Calls eZContentObject::clearCache(), which empties the in-memory cache of content objects of this request (it does not touch the view cache on disk). Useful in long templates that load many objects.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x