Subclassing Smartlet functionality
Smartlets can expose a rich set of features that can be configured using the Smartlet properties, the named arguments which are passed to each Smartlet in a viper call.
Not every feature can easily be exposed using properties however. Think of a Smartlet that collects some data from somewhere into a DataTable or Xml, and displays that information using formatting logic. It's not that easy to make the formatting as flexible as you wish to, with only a set of properties defined in the Smartlet public interface.
This is where sys.eval(expression, translationScope, fallbackScope) comes in.
This way, you can write your Smartlets just as usually, creating local translations for pieces of logic and calling this logic from the Smartlet (SML) item, only using another syntax:
Smartsite SXML | Copy Code |
---|---|
{sys.eval(pub_formatresults($data, smartlet.page(), smartlet.number()))} |
Now, simply place a pub_formatresults() translation in the Smartlet folder, make it 'Local' and 'Overridable', and you're all set. You have just made the pub_formatresults() logic subclassable. Anyone calling your Smartlet can now place another pub_formatresults() translation in their own scope to override your default handling.
Note that Contextual Translation Scoping feature, introduced in 1.4, makes the use of sys.eval() with scopes obsolete.