You are here: Home / Scripting

Scripting

As administrator on our DemoSite you may add a Templated Document a templated portlet which allows you add dynamic content to Plone.

Use cases

  • Using unfiltered HTML (<script> etc.).
  • Add dynamic lists and tables on pages.
  • Add dynamic e-mail texts, subject lines and addressees in rule actions.
  • Show different text content for logged-in and non logged-in (anonymous) users.
  • Generate simple text portlets with dynamic contents.

Example

For example, to get a list of all elements in the folder efficient usage you may put the following into the body text of a templated document:

{{ list_folder("efficient-usage").decode("utf-8") }}

Elements

Documents

Use the content type Templated Document.

Fields and widgets

TemplatedFieldIndex allows you to enter dynamic contents into a Templated Document, which may then generate the contents of a TextField () in your own content type.

Portlets

Templated Portlet also enables scripting for portlets. Thus the following use cases are possible:

  • Show portlets depending on the given language
  • Show portlets for specific users only
  • Show portlets depending on time settings

Emails

To enable for scripting the fields recipients, subject and message in emails it is possible to use Templated Mail Action.

Documentation

In the following section we describe the available variables and functions. Please note that the tags are described as functions and that for rendering () will have to be added.

For a Templated Document the following Plone variables are available:

portal

The Plone site, e.g.

{{ portal.Title().decode("utf-8") }}
context

The context of the Templated Document, e.g.

{{ context.Title().decode("utf-8") }}
{{ context.absolute_url().decode("utf-8") }}
portal_url

The URL of the Plone site, e.g.

<a href="{{ portal_url() }}">Home</a>
object_url
The URL of the object
user
The current user
request

Returns objects of the site according to the request, e.g.

{{ query({"portal_type":"News Item","sort_on":"Date","sort_order":"reverse"}) }}
portal_state

Information on the current site status, e.g.

  • is the user logged in?
  • which is the navigation root?
  • the portal title
  • active language

Because Jinja expects the strings to be ASCII or Unicode you will have to recode all outputs that may contain Umlaut characters or similar to UTF-8.

Moreover you can also display Viewlets and Provider:

{{ viewlet("portal.logo") }}
{{ provider("plone.rightcolumn") }}

Further information

Document Actions