Skip to content

Datamodel

Rainer Sulzbach edited this page Dec 2, 2019 · 18 revisions

Clownfish - datamodel

The datamodel defines how you can render provided data into templates. The basic of both template engines is a special directive.

Freemarker uses the ${xyz} syntax

Velocity uses the $xyz syntax

Where xyz is the internal variable that is going to be rendered into the output. Clownfish retrieves content in several ways.

Note: The provided examples use the Freemarker language.

Metainformation

Metainformation of a site is provided by the metainfo structure.

name description
title site title
name site name
description site description
encoding site encoding
contenttype site contenttype
locale site language info
alias alias path of the site

Assuming you have a site with the name homepage and the title Homepage of foo you can render the meta info as follows:

   <title>${metainfo.title}</title>
   ...
   <div>Name of the site: ${metainfo.name}</div>

The output will be:

   <title>Homepage of foo</title>
   ...
   <div>Name of the site: homepage</div>

Content in backend

The easiest way is a content in the backend. If you have already defined a class structure in the backend, then you can add content of that class type in the backend aswell. To retrieve the content data you have to link this content to a site in the siteoverview.

Every content that is stored in the backend is accessed by the sitecontent structure.

Simple content

Assuming you have created a site User and you have connected the content User1 to this site. To display the username of the content in the template use following directive:

<#if sitecontent.User1.name?has_content>
Name: ${sitecontent.User1.name}
<#/if>

When the name field of User1 is Harry the template would render

Name: Harry

Datalists

You can also define datalists with content of common classes. Then you are able to iterate over those lists and render the content to the output. Assuming you have created a datalist called Staff and you have a site called homepage you have to select this datalist in the siteoverview. The following code shows how to render the list in a template:

<#if sitecontent.Staff?has_content>
   <#assign staff = sitecontent.Staff?values>
   <#list staff?sort_by("name") as member>
      <div>${member.name}</div>
   </#list>
</#if>

The output could be:

   <div>Harry</div>
   <div>Sally</div>

AssetLibraries

You can group assets in libraries. In this case you are able to iterate over those libraries and render the content to the output. Assuming you have created an assetlibrary called HolidayImages and you have a site called holiday you have to select this assetlibrary in the content section of siteoverview. The following code shows how to render the list in a template:

<#if sitecontent.AssetLibrary.HolidayImages?has_content>
  <#list sitecontent.AssetLibrary.HolidayImages as image>
    <img src="GetAssetPreview?mediaid=${image.id}&width=200" alt="${image.name}" title="${image.name}" width="200" />
  </#list>
</#if>

The output could be:

   <img src="GetAssetPreview?mediaid=30&width=200" alt="holiday30.jpg" title="holiday30.jpg" width="200" />
   <img src="GetAssetPreview?mediaid=38&width=200" alt="holiday38.jpg" title="holiday38.jpg" width="200" />

GET/POST Parameters

You are able to work with the GET/POST parameters in the datamodel aswell. The structure name is parameter. Assuming you have called a site with a GET parameter like homepage?foo=bar then you can render this data like this:

<#if parameter.foo?has_content>
Foo is ${parameter.foo}
</#if>

The output looks like:

Foo is bar

Search results

With the Lucene search engine, you are able to fetch search results in a special way. You call the the result page with the URL http://localhost:9000/search/query where query is the search phrase. Internally the Lucene search engine retrieves a list of sites, where the searched content is used. This list is represented in the datamodel called searchlist. The search result page searchresult is being rendered and shown.

The searchlist is a HashMap of the found sites. You can access the fields via following example code:

<#if searchlist?has_content>
  <#list searchlist?keys as searchitem>
    <div>
      ${searchlist[searchitem].id} 
    </div>
    <div>
      ${searchlist[searchitem].name} 
    </div>
	<div>
      ${searchlist[searchitem].title} 
    </div>
	<div>
      ${searchlist[searchitem].description} 
    </div>
    <hr>
  </#list>
<#else>
  No result
</#if>

You can customize the searchresult template to fit your needs.

Clone this wiki locally