Accessing collection.cfg settings from Freemarker

Managed by | Updated .


This article explains how to use the values set in collection configuration from a Freemarker template. The collection configuration object in Freemarker contains all the collection's configuration values sourced from the collection.cfg (including defaults) and global.cfg.


The collection configuration settings are stored within a hidden data model object.

Collection configuration parameters can be used in Freemarker templates by accessing this object:

# Can also be used like this:

where CONFIGURATION_KEY is a key from collection.cfg or global.cfg. This call has the ability to see all user defined parameters found in the collection.cfg file and all default values. The funnelback_classic.ftl template provides a macro that can be used to read and display a collection.cfg parameter for the current collection being searched. The following is the macro body:

<#macro cfg>
  <#local key><#nested></#local>
  <#if key?exists && key!="" && question.collection.configuration.value(key)?exists>

The macro can then called in the template when you need to use the value. The call would look similar to this:



Example 1. cfg macro

Use the "cfg" macro to get the parameter to setup auto-completion:

<#import "/web/templates/modernui/funnelback_classic.ftl" as s/>
<script type="text/javascript">
//Query completion setup
jQuery(function()  {
    'enabled'   : 'enabled',
    'collection': 'collection-name',
    'program'   : '/s/search.html',
    'format'    : 'extended'
    'alpha'     : '<@s.cfg>auto-completion.alpha</@s.cfg>,
    'show'      : '<@s.cfg></@s.cfg>, 
    'sort'      : '<@s.cfg>auto-completion.sort</@s,cfg>,
    'length'    : '<@s.cfg>auto-completion.length</@s.cfg>,
    'delay'     : '<@s.cfg>auto-completion.delay</@s,cfg>,

Example 2. Directly access the data model configuration object

Access the data model hidden object with code similar to:

<#if question?exists && question.collection?exists 
  && question.collection.configuration.value("spelling_enabled")?exists
  && is_enabled(question.collection.configuration.value("spelling_enabled")) >
  <#--- Insert code for when configuration parameter exists and is enabled --->

Example 3. Print a link to email the search administrator.

In the Freemarker template:

<p>Contact the search administrator: <a href="mailto:${question.collection.configuration.value("admin_email")?url}">${question.collection.configuration.value("admin_email")}</a></p>

would result in the following being printed out by the template:

<p>Contact the search administrator: <a href=""></a></p>
Was this artcle helpful?

Type: Keywords:
Features: Frontend > Templating Frontend > Modern UI