.. ******************************************************************************* * MetaFactory.io R2 * Technical Documentation * * File name : Howto-Use-Snippets.rst * Created by : MetaFactory (Marnix Bochove) * Last update : 20-04-2021 * Updated by : Niels de Nies * * MetaFactory BV Amsterdam ******************************************************************************* .. include:: /inline-images.txt How to use snippets =================== Syntax for calling a snippet from XML: .. list-table:: :widths: 50 50 :header-rows: 0 :class: tight-table * - Freemarker - .. code-block:: xml ${fmsnippet.path.to.snippet} * - Velocity - .. code-block:: xml ${snippet.jhipster.html.overview} The result of the evaluated template is then inserted in the XML pattern at the place where it was called. |Eye M| :ref:`Example using Snippets ` shows how this works in practice. This is the way to go in MetaFactory when you wish to **evaluate a complex expression** for which the MetaFactory expression language does not have the required tool. Just print the result of the expression in your Freemarker snippet. When it comes to **generating plain text files**, simply use a single snippet within the XML pattern, as the below example shows. .. code-block:: xml yy ${fmsnippet.frontend.index.html} The third use case that we mentioned is to **extract and manipulate model data**. When doing so in a snippet you need access to the model (meta)data and likely to the pattern properties as well. **Access to the model** is provided by the :ref:`Model API `. Access to pattern properties is provided through the context object that is made available along with many other variables in the Freemarker or Velocity context. |Exclam M| To be able to use IDE autocompletion on these objects please first follow the instructions at :ref:`Configuring your IDE `. Through the context object you can then call a defined pattern property using the syntax: .. code-block:: context.getPatternPropertyValue(“full.property.name”). |Glasses M| Read more about :ref:`template engines `.