Custom templates - NatLibFi/Skosmos GitHub Wiki

HTML code is produced using Twig templates in Skosmos 3. There is a mechanism for customizing the HTML code that Skosmos produces via custom templates placed in the custom-templates directory. These can be used for two purposes: adding content to pages and overriding built-in templates.

Adding custom content to pages

Skosmos-generated pages have predefined slots, usually div elements, for inserting HTML content. For each slot, there is a corresponding custom-templates subdirectory where the site administrator can place Twig templates with the filename extension .twig. These are then inserted (in alphabetical order) to the corresponding slots. These slots are available:

  • about: the content will be inserted on the About page
  • footer: the content will be inserted in the footer element on every page type
  • html-head: the content will be inserted in the head element (useful for e.g. custom JavaScript)
  • landing-top and landing-bottom: the content will be added at the top/bottom of the landing page (before/after the main columns)
  • landing-start and landing-end: the content will be added inside the left (start) or right (column) of the landing page

Overriding Skosmos templates

Sometimes adding content to the predefined slots is not enough, for example if you want to remove elements from the UI or add content in another location outside the slots. Usually the best way for deeper customization is to use plugins, but that may not always be feasible.

You can override a specific Skosmos template by copying the .twig file from src/view/ into custom-templates and then editing it to suit your needs. Skosmos will prefer the version of the template under custom-templates.

Warning! Doing this will make future Skosmos upgrades more challenging! In a new version of Skosmos there may be changes in the original templates under src/view/ that will not be automatically transferred to the customized version under custom-templates. You will have to check for this and adapt your customized template according to the changes in the original Skosmos template.