Include
With the include tag you can access code stored in parts
Parts
The code of reconciliation templates is stored in a main part and in 15 optional parts. The main part is always loaded first, while the additional parts are only loaded when they are called. The parts can be accessed by using:
{% include "parts/name_of_a_part" %}
This code will only be executed if one of the parts is named name_of_a_part:
Using parts is especially useful to store translations or to store blocks of code that are executed multiple times in your template. It makes the main part cleaner and easier to read.
Bear in mind that liquid is executed from top to bottom. This means that if you declare and initialise variables before including a part, you can call upon those variables within that part.
Shared Parts
Shared parts have to be activated in your firm upon request to be utilised.
A shared part can be used in multiple templates.
When there is a snippet of code that is repeated in several templates a shared part can be useful. This would allow you to modify the code in one place when needed, and it will impact all the templates that use it. This can help prevent having to fix a bug over multiple places for a repetitive item.
E.g. A common use of the shared part would be for general translations that get used repetitively. If you would have made a spelling mistake, you will be able to edit the shared part and it will apply to all templates this translation tag was used in with this shared part. Keep in mind that the shared part is not taken from outside the template like a result tag, but the code is executed within the template at the exact place you have included it.
Once shared parts have been activated in your firm, you can add one by going to the "shared parts" subsection on the templates tab.
Let’s assume you have created a shared part labeled general_translations with the following information in it;
{% t="trademarks_t" en:"Trademarks" da:"Varemærker" default:"Varemærker" %}
Create a blank template
On the top navigation bar you will see the option “Add Shared Part"
When choosing this option you will see a dropdown of all the shared parts that have previously been created in this firm.
Add the shared part you wish to use. E.g. general_translations shared part, you can do this by using the include shared tag. Remember the part will only be included from the point this text has been added.
In the main body you can include the following .
{% include "shared/general_translations" %}
{{ trademarks_t }}
Output (in Danish) : Varemærker
Output (in any other language): Varemærker
Updating shared parts
In Silverfin, updating a template will create a new version of it in your firm. The same goes for shared parts. Additionally, updating a shared part will also create a new version for every template this shared part has been added to. You will receive an error message if you want to save code changes done to a template if a shared part has been updated in the meantime.
Set parameters or variables
The include tag also allows you to specify parameters or variables in the tag itself when including a part or shared part. Let's say you have a template structure with the local part "sum". In the main part you can include "sum" and pass specific values to it. The included part then performs the calculation and the result of that sum can be used in the main part. With this modular approach you can keep your code clean, organized and reusable.
The code in part main can look like this:
{% assign var_a = 4 %}
{% assign var_b = 5 %}
{% include 'parts/sum' a:var_a b:var_b %}
{{ sum }}
The code in part sum then looks like this:
{% assign sum = a+b %}
And the output will be:
This also works with shared parts. In the following example we have a shared part that builds an info text with a link to the relevant working paper. Whenever we want to print this info text, we need to first define which working paper is the relevant one. The code in the shared part "link_wp" looks like this:
{% ic %}{::infotext}
The information presented in this template comes from the {% linkto period.reconciliations.[working_paper_handle] %}{{ period.reconciliations.[working_paper_handle].name }}{% endlinkto %}.
{:/infotext}{% endic %}
In the main part of the template, we define which working paper is relevant by providing the handle and including the shared part.
{% include "shared/link_wp" working_paper_handle:"equity" %}
And then this is the outcome.
Updated 5 months ago