Using Smartlet Presets

Release 1.4 - ...

Smartlet Presets allow a site builder to restrict the number of Smartlet parameters that need to be (or can be) set by editors. A Smartlet Preset can be called using the named parameter preset on a smartlet.

Smartsite SXML CopyCode image Copy Code
{sml_feedreader(preset=nu_feed())}

By setting a value for a parameter, the user will no longer see an input field for this value. Values defined in a preset can not be changed in the viper call either. The following example throws an exception:

Smartsite SXML CopyCode image Copy Code
{sml_feedreader(preset=nu_feed(), url=http://www.google.com/)}

By specifying a default value for the parameter, the user can still change it, but doesn't need to bother. By setting a filter for a parameter, the input field can display different options in different situations.

A Smartlet Preset is a content item of content type "Smartlet Preset" (SMP), which inherits from Translation. The Replacement field can contain any SXML, but will have to contain an se:smartletpreset macro call to actually work as a preset. Here's the nu_feed preset from before:

Smartsite SXML CopyCode image Copy Code
<se:smartletpreset smartlet="sml_feedreader" displayname="Nu.nl RSS feed" inherit="CHANNELDEFAULTS">
 <se:collection>
  <se:member name="url">http://www.nu.nl/feeds/rss/algemeen.rss</se:member>
  <se:member name="showdescription" settingtype="defaultvalue">1</se:member>
 </se:collection>
</se:smartletpreset>

This is preset that tells the sml_feedreader Smartlet to display the RSS feed for the nu.nl news site by setting the url parameter. It also sets a defaultvalue for showdescription, so that descriptions will be shown if the user doesn't change the parameter explicitely. The displayname property overrides the displayname setting from the Smartlet definition.

The smartlet property specified in the preset is used by the Smartlet Editor to determine what smartlet to load when a preset is selected. Using a preset in a smartlet for which it was not intended can have unforseen consequences, but will not necessarily result in an exception. The following example will fail because the nu_feed() preset doesn't specify a poll item or folder:

Smartsite SXML CopyCode image Copy Code
{sml_poll(preset=nu_feed())}

The preset inherits from another preset with Code CHANNELDEFAULTS. Inheritance can be used to specify parameters that are the same for a number of or even all smartlets in your site. The Replacement field for channeldefaults may look something like:

Smartsite SXML CopyCode image Copy Code
<se:smartletpreset inherit="PRESET_BASE" cacheable="true">
 <se:collection>
  <se:member name="box">light</se:member>
  <se:member name="boxwidth"></se:member>
  <se:member name="boxheight"></se:member>
  <se:member name="boxid"></se:member>
  <se:member name="boxclass">default_channel</se:member>
  <se:member name="boxcaption"></se:member>
  <se:member name="boxattribs"></se:member>
 </se:collection>
</se:smartletpreset>

This preset is only used for inheritance, so it doesn't need to specify a smartlet or displayname property. Note that channeldefaults() in turn inherits from PRESET_BASE. There is no limit to the depth of inheritance.

For better performance Smartlet Presets can be cached. Add the parameter Cacheable="true" to your preset to have it cached. The complete set of properties, including those defined through inheritance, will be stored until the preset or one of its ancestors is edited in the cms. Caching is only possible if all ancestors of your preset are cacheable.

The preset caching mechanism depends on the SmartletPresetState class, which must be configured using the CTFP StateType on the Nr field of the SMP content type:

XML CopyCode image Copy Code
<?xml version="1.0" encoding="utf-8" ?>
<properties>
 <property name="StateType" type="String" roles="*">
  <![CDATA[Smartsite.Scf.SmartletPresetState, Smartsite.Scf]]>
 </property>
</properties>

Presets will only show up in a user's Smartlet Library if that user has been granted  SmartletEditorAccess for that preset or for the corresponding smartlet explicitely.