Hyper Open Edge Cloud

How To Add Content Variable to Documents

How To explaining how to add variables with standardized content to documents
  • Last Update:2016-02-11
  • Version:001
  • Language:en

Documents often contain predefined content blocks, for example a letter head. Sometimes it is necessary to vary this content, for example depending on the language the document is viewed in. This can be done using content variables along with a substitution mapping method.

Table of Contents

Defining a content variable and substitution method

Content variables are written ${[variable_name]} and can be placed anywhere inside the document source code. The content to be used for a variable has to be provided via a Substitution Mapping Method, whose ID must be provided in the respective field.

ERP5 FAQ | Content Variables - Screenshot Setting a Variable

Providing Content

In the above screenshot a method called WebPage_getContentVariableDict was specified to retrieve the content to be displayed on the page. Create this script in your respective portal_skin and provide the following code:

# Return text depending on language
portal = context.getPortalObject()
language = portal.Localizer.get_selected_language()

if language == "fr":
  return {
    "my_variable_name": 'Bonjour'
  }

if language == "de":
  return {
    "my_variable_name": 'Guten Tag'
  }

return {
  "my_variable_name": 'Hello'
}

Which goes here:

ERP5 FAQ | Content Variables - Screenshot Providing Object

The script will thus return an object with the content for the variable which will be automatically filled by ERP5 when the document is rendered.

Note: Putting the script in a specific portal_skin will throw an error when trying to view the same document through another skin. For example, if you have two websites on your instance with skins site_1 and site_2, putting the substitution mapping method in site 1 folder only will throw an error if trying to view the document through site 2. As a workaround, make sure scripts are accessible through a common skin.

Related Articles