SnippetBundle ============= The SnippetBundle contains the implementation to use snippets in Sulu. What is a Snippet ----------------- As the name suggests, a snippet is a small fragment on a page. However, unlike blocks, for example, which would also fit this description, the idea with snippets is reusability. As a section of a web page a snippet must be first universally maintained, and thereafter be reused anywhere on the website. An example on a website would be a social media section. In this section there would be logos of social services like Facebook and a link to the profile on the service. This section could of course also be built conventionally in a page template, but you would have to maintain it on each page. This is where snippets come into play. A snippet could be configured to cover exactly this use case and you would only have to maintain the profiles once and could reuse them at any point. Creating a Snippet Template --------------------------- In this example we'll creating a "Social Media" snippet to the page of Sulu. .. figure:: ../img/snippet-social-media.png Creating a snippet Template isn't really different like Page :doc:`../book/templates`. Create a XML File in your `config/template/snippets/` folder like the following example .. note:: The and the name of the XML must be the same! .. code-block:: xml Properties ---------- Properties are the same as Page :doc:`../book/templates`. Implement a Snippet in your Template ------------------------------------ Snippets are stored separately and are not accessible via the web page URL. So if we want to use a snippet on a page, we need to add the content type ":doc:`../reference/content-types/single_snippet_selection`" if we want to link one or ":doc:`../reference/content-types/snippet_selection`" for more snippets. .. figure:: ../img/social-media-snippet-selection.png .. code-block:: xml Footer Social Media Load Snippets from a Subfolder ------------------------------ By the means of configuration in `config/packages/sulu_admin.yaml` according to the following scheme it is also possible to load snippet templates from custom folders. .. code-block:: yaml sulu_core: content: structure: paths: event_snippets: path: "%kernel.project_dir%/config/template/events/snippets/" type: "snippet" In this example, a new Events folder has been specified. It is important that the key for the configuration remains unique for each config.