Chapter 4. Implementation

Table of Contents

1. Imps
1.1. Introduction
1.2. Configuration
1.3. Date Formatter
1.3.1. Introduction
1.3.2. Configuration
1.3.3. Methods
1.3.4. Examples
1.4. Number Formatter
1.4.1. Introduction
1.4.2. Methods
1.4.3. Examples
1.5. String Formatter
1.5.1. Introduction
1.5.2. Methods
1.5.3. Examples
1.6. RuleMatcherImp
1.6.1. Introduction
1.6.2. Methods
1.6.3. Examples
1.7. DatasourceQueryImp
1.7.1. Introduction
1.7.2. Methods
1.7.3. Examples
1.8. CalculatorImp
1.8.1. Introduction
1.8.2. Methods
1.8.3. Examples
1.9. GenticsPLinkImp
1.9.1. Introduction
1.9.2. Methods
1.9.3. Examples
1.10. VelocityToolsImp
1.10.1. Configuration
1.10.2. Default VelocityTools
1.11. I18nImp
1.11.1. Introduction
1.11.2. Methods
1.11.3. Examples
1.12. SortImp
1.12.1. Introduction
1.12.2. Methods
1.13. SortImp
1.13.1. Introduction
1.13.2. Methods
2. Plugins
2.1. Introduction
2.2. ViewPlugin
2.2.1. Introduction
2.2.2. Basic elements of a View
2.2.3. Property Paths
2.2.4. Parameters
2.2.5. Templates
2.2.5.1. Introduction
2.2.5.2. View Templates
2.2.5.3. Form Templates
2.2.5.4. Component Templates
2.2.5.5. Custom Action URLs / Events
2.2.6. Views
2.2.7. Components
2.2.7.1. All Components
2.2.7.2. Input Components
2.2.7.2.1. ButtonComponent
2.2.7.2.2. CaptchaComponent
2.2.7.2.3. CheckboxComponent
2.2.7.2.4. DatasourceSelectComponent
2.2.7.2.5. DateComponent
2.2.7.2.6. FileUploadComponent
2.2.7.2.7. NumberComponent
2.2.7.2.8. PasswordComponent
2.2.7.2.9. SelectComponent
2.2.7.2.10. TextAreaComponent
2.2.7.2.11. TextComponent
2.2.7.3. Display Components
2.2.7.3.1. DatasourceListComponent
2.2.7.3.2. DatasourceTreeComponent
2.2.7.3.3. DownloadComponent
2.2.7.3.4. FeedbackComponent
2.2.7.3.5. InformationComponent
2.2.7.3.6. LabelComponent
2.2.7.3.7. ListComponent
2.2.7.3.8. NestedFormComponent
2.2.7.3.9. TabComponent
2.2.7.3.10. VersionInformationComponent
2.2.7.3.11. VersioningComponent
2.2.8. Pluggable Actions
2.2.8.1. Introduction
2.2.8.2. Implementation
2.2.8.2.1. ActionContext
2.2.8.3. BinaryCallableActionResponseAction
2.2.8.4. BinaryToTextAction
2.2.8.5. CheckErrorsAction
2.2.8.6. CollectObjectsByRelationAction
2.2.8.7. CreateResolvablesAction
2.2.8.8. CSVDataImportAction
2.2.8.8.1. CSV header format
2.2.8.8.2. Skip line ranges
2.2.8.9. DatasourceAction
2.2.8.10. DownloadAction
2.2.8.11. EchoAction
2.2.8.12. Form2CNObjectAction
2.2.8.13. Form2ObjectAction
2.2.8.14. GeneralViewAction
2.2.8.15. ImpEncapsulateAction
2.2.8.16. JsonCallableActionResponseAction
2.2.8.17. Object2FormAction
2.2.8.18. PDF2TextAction
2.2.8.19. PlainCallableActionResponseAction
2.2.8.20. RenderTemplateAction
2.2.8.21. Resolvable2MapAction
2.2.8.22. RuleSearchAction
2.2.8.23. ScriptingAction
2.2.8.24. SendMailAction
2.2.8.25. SendRedirectAction
2.2.8.26. StoreFileAction
2.2.8.27. TextDiffAction
2.2.8.28. TriggerEventAction
2.2.8.29. TriggerPortalEventAction
2.2.8.30. URLLoaderAction
2.2.8.31. XSLTRenderAction
2.2.9. Callable Actions
2.2.9.1. Introduction
2.2.9.2. Template Variables
2.2.9.3. Input Parameters
3. Portal implementation
3.1. Introduction
3.2. Portal events
3.3. PBox events
3.4. ViewPlugin events
3.5. Portlet events
3.6. Portal Page events
3.7. Custom action events
3.8. Reactions
4. Portlet implementation
4.1. Introduction
4.2. Portlet Application
4.3. Portletdescriptor
4.4. Gentics Portletdescriptor
4.4.1. Introduction
4.4.2. Configuration
4.5. Portlet Cache
4.5.1. Portlet Cache Behaviour
5. Inter Portlet Communication
5.1. Java Property Getting and Setting
5.2. Reactions
6. Ajax
6.1. Ajax using Callable Actions
6.2. Ajax using JSR 286
6.3. AJAX enabled requests to the Server
6.3.1. Response Format of AJAX enabled requests API
6.3.2. Response of AJAX enabled requests with an invalid session
6.3.3. Portlet Reloading
6.3.3.1. Parameters
6.3.3.2. Templates
6.3.3.2.1. Portal Page Template
6.3.3.2.2. Portlet Frame Template
6.3.3.3. Client-side scripting
6.3.3.3.1. Automatic modification of URLs to be AJAX enabled
6.3.3.3.2. Generic handling of the response
6.3.3.3.3. Replace rendered portlets API
6.3.3.4. Restrictions and common pitfalls
6.3.3.5. Disabling it for single button
6.3.4. Portlet Drag & Drop
7. Property Setters
8. Portal Property Paths
8.1. Portal
8.2. Views
8.3. Modules
8.4. Positions (in Portal Page)
8.5. javax.portlet
9. Rules
9.1. Introduction
9.2. Variables
9.3. Operators
10. ExpressionParser
10.1. Introduction
10.2. Syntax
10.2.1. Introduction
10.2.2. Assignments
10.2.3. Assignment Operators
10.2.4. Expressions
10.2.5. Rules
10.2.6. Binary Operations
10.2.7. Unary Operators
10.2.8. Constants
10.2.9. Literals
10.2.10. Names and Variables
10.2.11. Functions
10.2.12. Evaluation priority
11. Templates
11.1. Portaltemplate
11.1.1. Introduction
11.1.2. pportal Tag
11.1.2.1. Defining Custom Actions
11.1.3. PNodes
11.1.4. PBoxes
11.2. Portlet Templates
11.3. Plugin Templates
11.4. TemplateEngine2
11.4.1. Introduction
11.4.2. Velocity
11.4.3. Context
12. Language
12.1. Introduction
12.2. Language Handling
13. Datasource
13.1. ContentRepository
13.1.1. Primary Key
13.1.2. Advantages
13.1.3. Database scheme
13.2. LDAP
13.2.1. Primary Key
13.2.2. Limitations
14. Portal Pages Implementation
14.1. Portal Page Templates
14.2. Portlet Frame Templates
14.3. Customizing portlet positions
14.3.1. Customizing portlet positions by property setting
14.3.2. Customizing portlet positions by URL
14.3.2.1. Request
14.3.2.2. Response
14.4. Persisting and restoring customized portlet positions
15. Portlet Specification 2.0 Support (JSR 286)

1. Imps

1.1. Introduction

Imps are small helpers, providing different functionality an implementer can use in portlets, supporting TemplateEngine2.

1.2. Configuration

Imps must be configured in Portalconfiguration file, see Section 8.4, “formatter-section” for detailed information. They provide basic functionality that shall be available in an easy and convenient way in every template. Generally, all configured imps are available through

$portal.imps.[id] 

1.3. Date Formatter

1.3.1. Introduction

Format a date in a standard or custom format, centrally managed and localizable. The class used is Class com.gentics.portalnode.formatter.GenticsDateFormatter .

By default, this imp will support the formats short , date and time (and any custom format passed to the methods directly). With the parameter configuration you can configure the path to a custom configuration file.

1.3.2. Configuration

Date formats have to be defined in META-INF/config/formatter/dateformatter.xml for use with the dateformatter's methods. See http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html and http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html for detailed information on formatting styles. Here is an example configuration:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- date formatter information -->
<date-formats default="STANDARD">
    <date-format id="STANDARD" defaultdate="MEDIUM" defaulttime="MEDIUM"/>
  	<date-format id="short" defaultdate="SHORT" defaulttime="SHORT"/>
    <date-format id="time" defaulttime="SHORT"/>
    <date-format id="date" defaultdate="MEDIUM"/>
    <date-format id="custom" defaultdate="dd.MM.yyyy" defaulttime="HH:mm">
      <date language="de">dd.MM.yyyy</date>
      <date language="en">dd/MM/yyyy</date>
      <time language="de">HH:mm</time>
      <time language="en">hh:mm a</time>
    </date-format>
</date-formats>					
				

Instead of the Formats SHORT, MEDIUM, STANDARD, LONG and FULL of the DateFormat class, it is also possible to use the Date and Time Patterns of the SimpleDateFormat class - this also applys for all Imp methods which have a parameter 'format'.

The subnodes <date> and <time> can be used for language specific date/time formats. Note that it is generally NOT necessary to define language specific formats for just generating formats that print e.g. month names. Month names will automatically be output in the current or given language. The language specific date/time formats are necessary, when the FORMAT itself shall be different, depending on the language. E.g. the separation characters between day, month and year shall be . for german and / for english.

1.3.3. Methods

All formats have to be predefined in file dateformatter.xml.

Table 4.1. Methods

Template SyntaxDescription
$portal.imps.date.format()retrieve current date formatted as defined in dateformatter.xml
$portal.imps.date.format(date)format provided "date" as defined in file dateformatter.xml
$portal.imps.date.format(date, format)format provided "date" with "format" defined in file dateformatter.xml
$portal.imps.date.format(date, format, languagecode)format provided "date" in the given language with "format" defined in file dateformatter.xml
$portal.imps.date.format(format)get current date formatted with "format" which is defined in file dateformatter.xml
$portal.imps.date.format(format, languagecode)get current date formatted in the given language with "format" which is defined in file dateformatter.xml
$portal.imps.date.parse(formatteddate)parse string "formatteddate" into a date object
$portal.imps.date.parse(formatteddate, format)parse string "formatteddate" which accords to "format" into a date object
$portal.imps.date.parse(formatteddate, format, languagecode)parse string "formatteddate" which accords to "format" in the given language into a date object
$portal.imps.date.fromTimestamp(timestamp)parse a unix timestamp into a date object
$portal.imps.date.formatDate(*) deprecated. use format(*) instead.
$portal.imps.date.parseDate(*) deprecated. use parse(*) instead.
$portal.imps.date.getRfc3339Timezone()

Get current timezone, formatted according to http://www.ietf.org/rfc/rfc3339.txt

$portal.imps.date.getRfc3339Timezone(date)

Get timezone of given date, formatted according to http://www.ietf.org/rfc/rfc3339.txt

$portal.imps.date.socialTime(date)

Print the given time in a "social time" format, e.g. like "10 seconds ago". The i18n Keys for localization are ($time is the placeholder for the time in numbers):

  • social.time.now (right now)
  • social.time.seconds ($time seconds ago)
  • social.time.minute ($time minute ago)
  • social.time.minutes ($time minutes ago)
  • social.time.hour ($time hour ago)
  • social.time.hours ($time hours ago)
  • social.time.day ($time day ago)
  • social.time.days ($time days ago)
  • social.time.week ($time week ago)
  • social.time.weeks ($time weeks ago)
  • social.time.month ($time month ago)
  • social.time.months ($time months ago)
  • social.time.year ($time year ago)
  • social.time.years ($time years ago)

1.3.4. Examples

The GenticsDateFormatter may be used to format dates in the way that it was defined in the dateformatter.xml file. Syntax:

$portal.imps.date.format()       ## Mar 6, 2006 1:31:46 PM
$portal.imps.date.format("date") ## Mar 6, 2006
$portal.imps.date.format("time") ## 1:31 PM
$portal.imps.date.parse("Mar 6, 2006 1:31:46 PM",
    "STANDARD").hours            ## 13
								

1.4. Number Formatter

1.4.1. Introduction

The Number Formatter Imp provides you with automated formatting for decimal numbers, currencies and filesizes. Locales are also taken into account. Furthermore it provides you with rounding facilities. The class used is com.gentics.portalnode.formatter.GenticsNumberFormatter. There are no configuration parameters.

1.4.2. Methods

These are the methods provided by the Number Formatter. Please keep in mind that decimal numbers have to be provided as strings since velocity is incapable of handling floating point notation directly. All floating point numbers are formatted according to the portal's current locale.

Table 4.2. Methods

Template SyntaxDescription
$portal.imps.number.floor(string) top the given value down
$portal.imps.number.ceil(string) round the value up
$portal.imps.number.round(string, [int]) will round a floating point value for you. if you want to round to a specific precision use the optional parameter to set the number of digits to display.
$portal.imps.number.currency(string, [string]) this function ist used to format a floating point value according to locale settings. A desired locale (eg. en_US, de_AT, ...) may be provided via the second (optional) parameter. If there is no locale provided the function will stick to the portal's locale which is currently selectet and therefore will adapt output if the user switches between languages.
$portal.imps.number.filesize(string, [int]) automatically convert a filesize provided in bytes to the highest unit possible. Currently the largest unit supported is Yottabyte (YB, equals 2^80) which should suit well for all tasks. Decimal prcision can be defined using the second (optional) parameter. If left out a precision of 2 is applied by default.
$portal.imps.number.bytesTo(string, string, [precision])convert a filesize from bytes to a desired target unit. The filesize is filled in as the first parameter, the desired unit es the second. Units supported are: "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB". The third (optional) parameter describes the decimal precision which is applied to the output and defaults to 2.
$portal.imps.number.format(string) format a number according to current locale

1.4.3. Examples

Here are some basic use cases of the Number Formatter.

$portal.imps.number.ceil("17.25")             ## Output: 18
$portal.imps.number.floor("17.25")            ## Output: 17
$portal.imps.number.round("17.25")            ## Output: 17
$portal.imps.number.round("17.25",1)          ## Output: 17.3
$portal.imps.number.currency("17.25")         ## Output: €17,25
$portal.imps.number.currency("17.25","en_US") ## Output: $17.25
$portal.imps.number.filesize("1048576")       ## Output: 1 MB
$portal.imps.number.filesize("150000", 2)     ## Output: 146.48 KB
$portal.imps.number.bytesTo("1048576", "KB")  ## Output: 1024.00 KB
$portal.imps.number.bytesTo("1048576", "MB")  ## Output: 1.00 MB
$portal.imps.number.format("1048576.123")     ## Output; 1,048,576.123
				

1.5. String Formatter

1.5.1. Introduction

Format or work with strings for usage in teasers, html, javascript, etc. The class used is com.gentics.portalnode.formatter.GenticsStringFormatter . There are no configuration parameters.

1.5.2. Methods

[Note]Note

All methods requiring a regular expression use the syntax as described in the Java API documentation for the class java.util.regex.Pattern

Table 4.3. Methods

Template SyntaxDescription
$portal.imps.string.escapeHTML(string) escapes special characters (like '<', '>', '&') with entities
$portal.imps.string.escapeJS(string) escapes special javascript characters (like '\', ''', '"') with \ to make them save for output in javascript strings
$portal.imps.string.stripML(string) Removes the embedded HTML tags from user input string to prevent potential problems (in fact it removes anything beginning with < and ending with > ).
$portal.imps.string.trim(string, length) trims the given string to be no longer than length characters
$portal.imps.string.regexp(string, pattern, replacement) replaces in string all occurances of pattern with replacement
$portal.imps.string.testRegex(string, regex) tests whether string matches regex
$portal.imps.string.trimWords(string, length) trims all words in string to be no longer than length. longer words are trimmed using ... as ellipsis.
$portal.imps.string.trimWords(string, length, ellipsis) trims all words in string to be no longer than length. longer words are trimmed using ellipsis.
$portal.imps.string.trimWords(string, length, ellipsis, template) trims all words in string to be no longer than length. longer words are replaced by template, where $trimmedword will be replaced by the trimmed word and $word with the original one
$portal.imps.string.encodeURL(string[, string])URL - encodes the specified String and returns it. The encoding used to get the bytes for unsafe characters defaults to "utf-8" but may be given as second parameter (e.g. "iso-8859-1").
$portal.imps.string.implode(Array/Collection, seperator) Converts the given array or collection into a string seperating the items with the given string seperator.
$portal.imps.string.implode(Array/Collection, separator, prefix, postfix) See above. In addition the items will be pre and postfixed.
$portal.imps.string.toUpper(string) Converts the given string to all uppercase.
$portal.imps.string.md5(string) Compute the md5 hash of the given String.

1.5.3. Examples

Example 4.1. implode

Convert an array of numbers into a special string.

Array: [1,2,3]
												Separator: ;
												Prefix: (
												Postfix: )
												Result: (1);(2);(3)
											

Example 4.2. escapeHTML

Fill a HTML textbox inside a velocity template with an escaped value.

<textarea name="text">
$portal.imps.string.escapeHTML($value)
</textarea>
				

Example 4.3. escapeJS

<script language="JavaScript">
	var message = "$portal.imps.string.escapeJS($value)";
	alert(message);					
</script>
				

1.6. RuleMatcherImp

1.6.1. Introduction

The RuleMatcherImp is used to evaluate rules in templates. The corresponding class is com.gentics.portalnode.formatter.GenticsRuleMatcherImp . There are no configuration parameters for the RuleMatcherImp.

1.6.2. Methods

Table 4.4. Methods

Template SyntaxDescription
$portal.imps.rule.matches(rulestring) Evaluates the given rule and returns true when the rule matches (false if not)

1.6.3. Examples

#if($portal.imps.rule.matches("portal.user.systemrole CONTAINSONEOF admin")
	Welcome admin!
#else
	Welcome user!
#end
				

1.7. DatasourceQueryImp

1.7.1. Introduction

Query any data accessible by supported datasources by rules, loop through results. Support for nestable queries. The class used is com.gentics.portalnode.formatter.DatasourceQueryImp . There are no configuration parameters.

1.7.2. Methods

Table 4.5. Methods

Template SyntaxDescription
$portal.imps.query.rule = [rulestring]set the primary rule (for fetching objects)
$portal.imps.query.sortBy = [sortBy]Sort results by a certain attribute; may also contain a comma separated list of attributes. (optional)
$portal.imps.query.sortOrder = [sortOrder]set the sortorder to be used. Possible values are:
  • ASC or ASCENDING for ascending sortorder (default)

  • DESC or DESCENDING for descending sortorder

  • NONE for no specific sort order

$portal.imps.query.data.[id] = [data]set the data parameter [id] to the value [data]. Data parameters can be evaluated in rules and subrules
$portal.imps.query.subrules.[id] = [subrulestring]set a named subrule. Subrules can be used in primary rules and other subrules
$portal.imps.query.resultGet the list of objects filtered by the primary rule
$portal.imps.query.countGet the number of objects filtered by the primary rule
$portal.imps.query.reset()Reset all previously set rules, subrules and data
$portal.imps.query.versionDateProperty versionDate (date to be used for versioned queries if the datasource supports versioning)
$portal.imps.query.resetVersionDate()Reset property versionDate (query on current data)
$portal.imps.query.versioningTrue when the datasource supports versioning false if not
$portal.imps.query.getDifference(List list1, List list2)Get the difference of list1 and list2, that means a list of objects contained in list1 but not in list2
$portal.imps.query.getDifferenceCount(List list1, List list2)Get the difference count of list1 and list2, that means the number of objects contained in list1 but not in list2
$portal.imps.query.getIntersection($list1, $list2)Get the intersection of list1 and list2, the result is a list of pairs, every element holds in $pair.left the object from $list1 and in $pair.right the object from $list2
$portal.imps.query.prefillAttributes = [attributeslist]Set a list of attributes (including linked objects and their attributes) that shall be prefilled in the fetched objects (increased performance)

1.7.3. Examples

## get all companies
#set ($portal.imps.query.rule = "object.obj_type == 50001")
#set ($companies = $portal.imps.query.result)

## for each company, get all users
#set ($portal.imps.query.rule = "object.obj_type == 50000 &&
    object.organisation == data.organisation")
#set ($portal.imps.query.prefillAttributes = ['firstname','lastname'])
#foreach ($company in $companies)
#set ($portal.imps.query.data.organisation = $company.contentid)
#set ($portal.imps.query.sortOrder = "ASC")
#set ($portal.imps.query.sortBy = "lastname")
#set ($users = $portal.imps.query.result)
<table>
#foreach($user in $users)
  <tr>
    <td>$user.firstname</td>
    <td>$user.lastname</td>
  </tr>
#end
</table>
#end
				

1.8. CalculatorImp

1.8.1. Introduction

Can be used for calculations in templates. The calculator imp supports arbitrary calculator variables that can be used independently. The class used is com.gentics.portalnode.formatter.CalculatorImp. There are no configuration parameters.

1.8.2. Methods

Table 4.6. Methods

Template SyntaxDescription
$portal.imps.calc.[id].reset()reset the calculator variable [id] to 0
$portal.imps.calc.[id].add([number])add a value to the calculator variable [id]
$portal.imps.calc.[id].sub([number])subtract a value from the calculator variable [id]
$portal.imps.calc.[id].mult([number])multiply the calculator variable [id] with a value
$portal.imps.calc.[id].div([number])divide the calculator variable [id] by a value
$portal.imps.calc.[id].precision = [int]set precision to be used for calculations
$portal.imps.calc.get([id])See $portal.imps.calc.[id]
$portal.imps.calc.[id]get the current value of the calculator variable [id]
$portal.imps.calc.[id].formatget the current value of the calculator variable [id] formatted according to current locale

1.8.3. Examples

## reset the variables mycalc1 and mycalc2
$portal.imps.calc.mycalc1.reset()
$portal.imps.calc.mycalc2.reset()

## change the variables
$portal.imps.calc.mycalc1.add("1.5")
$portal.imps.calc.mycalc2.sub("7000")
$portal.imps.calc.mycalc2.add($portal.imps.calc.mycalc1)

## mycalc2 should now be -6998.5
Result: mycalc2 = <strong>$portal.imps.calc.mycalc2</strong>
				

1.9. GenticsPLinkImp

1.9.1. Introduction

Can be used to generate Plinks (links to content). The class used is com.gentics.portalnode.formatter.GenticsPLinkImp. There are no configuration parameters.

1.9.2. Methods

Table 4.7. Methods

Template SyntaxDescription
$portal.imps.link.to([contentid]) Generate the URL to the given contentid. The URL will not be XML escaped. When this method is used inside a GenticsContentModule, the link will automatically be directed to that portlet, otherwise the portal-wide configured plinkprocessor will be used.
$portal.imps.link.to([contentid], [escapeXML]) Generate the URL to the given contentid. When escapeXML is set to true , the generated URL will be XML escaped. When this method is used inside a GenticsContentModule, the link will automatically be directed to that portlet, otherwise the portal-wide configured plinkprocessor will be used.
$portal.imps.link.to([contentid], [portletid]) Generate the URL to the given contentid. The URL will not be XML escaped. The URL will be directed to the portlet [portletid].
$portal.imps.link.to([contentid], [portletid], [escapeXML]) Generate the URL to the given contentid. When escapeXML is set to true , the generated URL will be XML escaped. The URL will be directed to the portlet [portletid].

1.9.3. Examples

Find more <a href="$portal.imps.link.to("10007.1234")">information</a>
				

1.10. VelocityToolsImp

The VelocityToolsImp is a wrapper for the Velocity Tools. The syntax of each Tool is described on the Velocity Tools Website.

1.10.1. Configuration

Optionally it is possible to configure the location of a xml file (toolbox.xml) as used by XMLToolboxManager. For this define the parameter configuration with the file path to the .xml file. (System properties ${myprop} are resolved)

1.10.2. Default VelocityTools

The following default VelocityTools are available without changing configuration:

  • $portal.imps.velocityTools.date - DateTool
  • $portal.imps.velocityTools.math - MathTool
  • $portal.imps.velocityTools.number - NumberTool
  • $portal.imps.velocityTools.render - RenderTool
  • $portal.imps.velocityTools.esc - EscapeTool
  • $portal.imps.velocityTools.alternator - AlternatorTool
  • $portal.imps.velocityTools.parser - ParserTool
  • $portal.imps.velocityTools.list - ListTool
  • $portal.imps.velocityTools.sort - SortTool
  • $portal.imps.velocityTools.iterator - IteratorTool

Example 4.4. Simple Example of the usage of EscapeTool and RenderTool

## We don't want to type the whole path each time...
#set( $tools = $portal.imps.velocityTools )
#set( $torender = 
  "$tools.esc.getHash()set( $tools.esc.getD()harhar = 'World' ) \
   Hello $tools.esc.getD()harhar !!!" )
Rendering: $torender
<pre>$tools.render.eval( $ctx, $torender )</pre>
					

1.11. I18nImp

1.11.1. Introduction

Can be used to generate internationalized output in templates. The class used is com.gentics.portalnode.formatter.I18nImp. There are no configuration parameters.

1.11.2. Methods

Table 4.8. Methods

Template SyntaxDescription
$portal.imps.i18n.languageThe currently set language, or null if the Imp shall use the current portal language. Note that setting the language of an I18nImp does not affect the portal language.
$portal.imps.i18n.resetLanguage()Method to reset the currently used language.
$portal.imps.i18n.translate(String key)Translate the given key into the current language (either set by $portal.imps.i18n.language or the portal language).
$portal.imps.i18n.translate(String key, String languageId)Translate the given key into the language with id languageId.

1.11.3. Examples

## set the language to English
#set($portal.imps.i18n.language = "en")
## translate this to the current language (English)
$portal.imps.i18n.translate("welcome")
## and this to German
$portal.imps.i18n.translate("welcome", "de")
				

1.12. SortImp

1.12.1. Introduction

Can be used to sort Resolvables by arbitrary properties. The class used is com.gentics.portalnode.formatter.SortImp. There are no configuration parameters.

[Note]Note

Implementation note: The given sort properties might also be paths to properties of resolved subobjects. The general syntax for sort properties is [path.to.property][:asc|:desc] where the postfix determines the sortorder. If neither :asc nor :desc is given, the sorting will be done ascending for this property.

1.12.2. Methods

Table 4.9. Methods

Template SyntaxDescription
$portal.imps.sorter.sort(Collection collection, String[] properties[, boolean caseSensitive][, String languageCode])

Sort the given collection (might also be an array or a map) by the given list of properties. The sortorder can be independently set for each property in the list. When sorting by only one property, one can also pass a single String instead of an array of Strings as value for the parameter properties .

The function parameter caseSensitive is optional.

The function parameter languageCode is optional, and - if given - must be a lower-case, two-letter code as defined by ISO-639-1. See http://www.loc.gov/standards/iso639-2/php/code_list.php for details.

1.13. SortImp

1.13.1. Introduction

This Imp can be used to get content from a given URL and include it into the template. The class used is com.gentics.portalnode.formatter.URLIncludeImp. There are no configuration parameters.

1.13.2. Methods

Table 4.10. Methods

Template SyntaxDescription
$portal.imps.url.include(String url[, int cacheLifeTime[, int timeout[, String defaultContent]]])

Will include the content fetched from the given url.

The content will be cached for cacheLifeTime seconds (defaults to 300 seconds).

The parameter timeout defines a timeout for trying to contact the given URL in milliseconds (defaults to 2000 ms).

If the parameter defaultContent is set to a String (including the empty String), this String will be output in case of a connection error. When set to null, this will cause a render error.