Pregunta a l'IA
Hola! Pregunta'm qualsevol cosa
Core
Core content

Core content macros help creating pages that are rendered using dynamic content.

With readers

Macros with readers help formatting data on properties, XML and JSON files.

Core
Macro parser

Expands into web application's context.

{@ webroot }

Expends into site name.

{@ site }

Shows current rendering context.

{@ rendering }

Elephant language.

{@ lang }

Calls modules' user summaries and show the results.

{@ user-summary [ : mode ] }
Atributs Descripció Opcions Per defecte
mode Mode to use. init

{@ user-contents }

Reads and renders file content.

{@ include : content-file }
Atributs Descripció Opcions Per defecte
content-file System file to show.

Writes parameter with name value or default when null.

{@ param : name [ : default ] }
Atributs Descripció Opcions Per defecte
name Attribute name.
default Default value.

Renders context content. If stopper is set to true, stops when finding a line starting with .

{@ render : context [ : stopper ] }
Atributs Descripció Opcions Per defecte
context Elephant context for links.
stopper Whether rendering should stop.

Writes current date, time or both using diferent localized formats.

{@ date [ : mode [ : format ] ] }
Atributs Descripció Opcions Per defecte
mode Mode to use. date, all, time date
format Format used to show the value. short, medium, long, full short

Renders the feed at url.

{@ feed : url }
Atributs Descripció Opcions Per defecte
url Uniform Resource Locator.

Creates an Elephant marker within context with name. Elephant markers are initialized with correct locale and constructor as variable.

{@ marker : tmpl-root : template : value-map }
Atributs Descripció Opcions Per defecte
tmpl-root Templates root.
template Template used to show the items.
value-map Values using the form variable=value separated by ;

Creates an Elephant marker within context with name. The repository-file is stored in props.

{@ marker-props : tmpl-root : template : repository-file }
Atributs Descripció Opcions Per defecte
tmpl-root Templates root.
template Template used to show the items.
repository-file Name of the repository file.

Creates an Elephant marker within context with name. The repository-file is stored in doc.

{@ marker-xml : tmpl-root : template : repository-file }
Atributs Descripció Opcions Per defecte
tmpl-root Templates root.
template Template used to show the items.
repository-file Name of the repository file.

Creates an Elephant marker within context with name. The repository-file is stored in json.

{@ marker-json : tmpl-root : template : repository-file }
Atributs Descripció Opcions Per defecte
tmpl-root Templates root.
template Template used to show the items.
repository-file Name of the repository file.

Writes a json array of files matching path and pattern. The array can be as is, sorted or shuffled.

{@ files : folder : pattern : mode }
Atributs Descripció Opcions Per defecte
folder Folder location.
pattern The pattern items must match.
mode Mode to use. normal, sort, shuffle

Creates a frame with url content. If url starts with '/' application context is automatically inserted.

{@ frame : url : width : height }
Atributs Descripció Opcions Per defecte
url Uniform Resource Locator.
width CSS style width.
height CSS style height.

Gets resource value and renders as mode. Mode is an integer optional parameter.

{@ res : resource-key [ : string-mode ] }
Atributs Descripció Opcions Per defecte
resource-key Key used to locate de resource.
string-mode Possible values are: 0 No transform, 1 Capitalized, 2 To upper case, 3 To lower case. 0

{@ i18n : resource [ : string-mode ] }
Atributs Descripció Opcions Per defecte
resource
string-mode Possible values are: 0 No transform, 1 Capitalized, 2 To upper case, 3 To lower case. 0

Writes a random number starting at zero and up to limit minus one.

{@ random : random-limit }
Atributs Descripció Opcions Per defecte
random-limit Random values ceil.

Elephant context for links.

{@ context : level }
Atributs Descripció Opcions Per defecte
level Number of the item level.

Writes currently logged user's name, identifier or email.

{@ user [ : mode ] }
Atributs Descripció Opcions Per defecte
mode Mode to use. name, id, email name

Writes true or false expressions depending on whether role:attribute pair are satisfied.

{@ if : role : attribute : true-expression : false-expression }
Atributs Descripció Opcions Per defecte
role Entity role part.
attribute Permission part.
true-expression When comparison is true.
false-expression When comparison is false.

Writes true or false expressions depending on whether cookie value equals value.

{@ ifcookie : cookie : value : true-expression : false-expression }
Atributs Descripció Opcions Per defecte
cookie Cookie name.
value Value to search for.
true-expression When comparison is true.
false-expression When comparison is false.

Writes true or false expressions depending on whether class could be instantiated.

{@ class : class-name : true-expression : false-expression }
Atributs Descripció Opcions Per defecte
class-name Java class name.
true-expression When comparison is true.
false-expression When comparison is false.

Writes true or false expressions depending on whether value1 equals value2.

{@ equals : value : value : true-expression : false-expression }
Atributs Descripció Opcions Per defecte
value Value to search for.
value Value to search for.
true-expression When comparison is true.
false-expression When comparison is false.

Renders object's attribute as string. object can also be an entityPath.

{@ object : ref-object : attribute }
Atributs Descripció Opcions Per defecte
ref-object Attribute name holding the object or an entityPath.
attribute Renders attribute's value as string.

Renders attribute's value as string.

{@ attribute : attribute [ : format ] }
Atributs Descripció Opcions Per defecte
attribute Renders attribute's value as string.
format Format used to show the value.

Renders entity using name and description.

{@ entity : entityPath : fmt-name-desc }
Atributs Descripció Opcions Per defecte
entityPath Path to a entity.
fmt-name-desc Format, as in String.format(), with entity name and description as parameters.

Renders the entity represented by path calling plugin and using template if specified.

{@ entity-ctrl : plugin : entityPath [ : template ] }
Atributs Descripció Opcions Per defecte
plugin Plugin name.
entityPath Path to a entity.
template Template used to show the items.

Writes cookie value. If optional value is defined, then sets cookie value.

{@ cookie : name [ : value ] }
Atributs Descripció Opcions Per defecte
name Attribute name.
value Value to be set when defined.

Indicator name.

{@ indicator : storeClass : indicatorClass : entityPath : indicator [ : relatedPath ] }
Atributs Descripció Opcions Per defecte
storeClass
indicatorClass
entityPath Path to a entity.
indicator Indicator name.
relatedPath

{@ entry-point : identifier [ : values ] }
Atributs Descripció Opcions Per defecte
identifier
values

Macros with readers, how does it work?

The easiest way to read a file is store it in context's repository and access it with */file. The * will expand into rendering context repository. For example:

{@marker-xml:xml:doc:*/doc.xml}

Reads doc.xml in current repository and passes its data to [Template_root]/xml/docTemplate.html to be formatted.

Reading properties

Properties are stored in props list in the same order they are stored on disc. You can iterate props with #list.

<#list props?keys as key>
   <#assign value=props[key]/>
   // do something with key and value
   ...
< /#list>

Reading XML

XML documents are stored in doc model. You can iterate the elements using dot syntax and iterate collections as you would usually do for any other data. The XML model is the FreeMarker NodeModel.

Reading JSON

JSON files are stored in json model. To access a root, use json.read("$.root"). If the root is a list, use json.list("$.root"). Once retrieved the root, you can iterate the elements using dot syntax and iterate collections as you would usually do for any other data. The JSON model is a subset of the JsonPath DocumentContext, optimized for templates usage.

The JSON books example

The data:

{
  "book": [
    {
      "title": "...",
      "author": "...",
      "excerpt": "...",
      "availability": "...",
      "link": "...",
      "filelink": "...",
      "imagelink": "...",
      "pages": 0
    },
    {
      ...
    },
    ...
  ]
}

The template (Semantic-UI):

<div class="ui divided items">
  <#list json.list("$.book") as book>
    <div class="item">
      <a class="ui tiny image" href="${book.link}">
        <img src="${book.imagelink}"/>
      </a>
      <div class="content">
        <a class="header" href="${book.link}">${book.title}</a>
        <div class="meta">
          ${book.author}
        </div>
        <div class="description">
          ${book.excerpt}
        </div>
        <div class="extra">
          ${book.availability}
          <#if book.filelink?has_content>
            <a target="_new" href="${book.filelink}">${book.pages}</a>
          < /#if>
        </div>
      </div>
    </div>
  < /#list>
</div>