WCM Forms Rendering

Showing results for 
Search instead for 
Did you mean: 

WCM Forms Rendering

0 0 1,257

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Once the content data is captured (via XForms) as XML instance documents, it needs to be rendered to site visitors in a human-readable format (typically HTML).  This transformation can be done at request time (by converting the XML to HTML on the fly) or at authoring time, via the use of 'renditioning templates'.

Alfresco provides two renditioning engine implementations, one which uses XSL templates, and the other freemarker.  In both cases, the form instance data (XML) is passed to the template to be rendered.  The following are simple examples of how a simple XML document can be processed by both FreeMarker and XSL.


Given the XML schema:

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
  <xs:element name='simple'>
        <xs:element name='string' type='xs:normalizedString'/>

The user will open an XForm, and fill in one string.  The resultant XML is as follows:


Rendering Template 1 - Freemarker

You can now use the following FreeMarker rendering engine template:



Rendering Template 2 - XSL

Alternatively, you could use an XSL rendering engine template:

<xsl:stylesheet version='1'
   <xsl:output method='html' indent='yes' encoding='UTF-8' version='4.01'
               doctype-public='-//W3C//DTD HTML 4.01 Transitional//EN'
   <xsl:template match='/'>
         <xsl:value-of select='/simple/string'/>

Resulting HTML output rendition (using either FreeMarker or XSL):


Variables and Functions exposed to Rendering Engine

Alfresco makes a set of helper variables and functions available within both FreeMarker and XSL rendering engine templates.  These allow the author of a rendering engine template to perform conditional logic, extract content from the repository.

Here's a list of the variables and functions provided:

avm_sandbox_url: A variable that provides the URL to the root of the current sandbox.  For example:  http://www-alfresco2--admin.avm.alfresco.org:8180
form_instance_data_file_name: A variable that provides the name of the file containing the form instance data being used.
rendition_file_name: A variable provides the file name of the rendition being produced.
parent_path: A variable that provides the parent_path of the rendition being produced.  This is an AVM path  of the form:  alfresco2-admin-main:/appBase/avm_webapps.
request_context_path: ??? http://forums.alfresco.com/viewtopic.php?p=25552&sid=3f598085a96299c4e29653f8fda3408f

parseXMLDocument(String virtualPath): A function returning the root element of the XML file at the given virtualPath.  A 'virtual path' is virtualized path within the AVM repository.  The most recent version within the repository is assumed (i.e.: version -1).
parseXMLDocuments(String formName, String virtualPath):  A function returning an iterator over the root elements of the XML documents at directory given by virtualPath; this interator only contains those form instance data files generated by formName.  In FreeMarker, the return value of this function is a list.  In XSL, the return value is a node-set.  In either case, the attribute alf:file_name  is set on each element;  this contains the name of the file that was parsed.

In Freemarker, all variables and functions are in a hash called alf.  For example, to access the value of the parent_path variable, use the FreeMarker expression:


In XSL, all variables are in the namespace alf.  Thus, to access the value of the parent_path, use the XSL expression:

<xsl:value-of select='$alf:parent_path'/>

Examples can be found in the source tree in FTL and in XSL:


Template Inclusion

Both Freemarker and XSL support including one template (or stylesheet) from another using the #include directive and xsl:include tag respectively.  The template to include can be either a path within the virtualized webapp the form is configured for, or secondarily the name of the file to include in the form's folder within the Web Forms space in the Data Dictionary.

More Freemarker Rendering Template Examples

NOTE Refer to Freemarker docs for more details.

Example - Using qualified elements namespaces


<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
  <xs:element name='simple'>
        <xs:element name='string' type='xs:normalizedString'/>

Form instance data:


FreeMarker template:

HTML output rendition:


Example - Using NameSpace Prefixes

Example - Using Variable Assignment

Return to WCM Forms Developer Guide