Dashboard > Hippo CMS > ... > 03. Developing templates > Preprocessing templates
Preprocessing templates
Added by Andrew Savory, last edited by Andrew Savory on Oct 10, 2006  (view change)
Labels: 
(None)


You can apply preprocessing to templates to populate new documents with values - for example setting the current date, or adding default content. This is done by creating a transformer in XSLT that will convert your template document to a template document with content.

For example, to add a new agenda item, which may look like:

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <meta>
    <title></title>
    <date day="1" month="1" year="1970"/>
    <keywords keywords="" />
  </meta>
  <content>
  </content>
</document>

If you want the actual current date filled in after creation, have a folder structure in the root of your staging site that looks like: default.preview/configuration/editing/transformers/insertcontent.xsl where insertcontent.xsl could look something like

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Transforms content into the newly inserted template.
-->
<xsl:stylesheet 
     version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
     xmlns:date="http://exslt.org/dates-and-times" 
     extension-element-prefixes="date"
     exclude-result-prefixes="date i18n">


  <xsl:variable name="nYear" select="date:year()"/>
  <xsl:variable name="nDay" select="date:day-in-month()"/>
  <xsl:variable name="nMonth" select="date:month-in-year()+1"/>

  <xsl:template match="/">
    <xsl:apply-templates select="*">
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="date">
    <date day="{$nDay}" month="{$nMonth}" year="{$nYear}"/>
  </xsl:template>
  <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:template> 

</xsl:stylesheet>

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.7 Build:#813 Aug 28, 2007) - Bug/feature request - Contact Administrators