LambdaActions

From OPENRESEARCH th copy Wiki
Jump to navigation Jump to search

LambdaActions

Queries

SQL

SMW

The defined smw query is executed and is returned as list of dicts. Only results for query variables are returned and used as keys for the further processing in the actions, for example as input for a jinja template. The smw query should be enclosed by HTML pre-tags.

Examples

Query
TopicQuery

Actions

Python

Jinja Templates

To define jinja templates the Property:Sourcecode lang must be "jinja" and the Property:Sourcecode text must contain the jinja template and should be enclosed by HTML pre-tags. The template is rendered and stored as a wikipage. In jinja template actions, the access to the context dict is limited since the template is executed for each result separetly. This means that instead of rows the context only provides row, the access to the currently processed row of rows. Distinct to the use of the context in EchoCode the keys of the context dict can be directly referenced because the context dict is handed over to the jinja render function. With the use of jinja statements and the objects in context it is possible to execute python code, running a smw query for example, in the template.

Special Attributes

The following attributes should be define in every jinja template action:

{% set pagetitle = ""%}
{% set pagetitle_prefix = "ListOf:"%}

The attribute "pagetitle" defines the title of the in which the rendered template is stored. If the attribute is not defined the attribute "name" of the result row is used as page. Additionally the attribute "pagetitle_prefix" is added as prefix to the title.

Examples

Template
CreateHelpPageTest
CreateListOf

Context

Dict that can be accessed by actions, it conains:


Key Description
rows Query result
smw SMW object for querying the wiki
wikiclient client to modify the wiki (use with care)