custom
The custom drop is a special kind of drop. It can be called on period, detail, account and company. It allows to add custom data of any kind to a specific object in Silverfin.
To reference an item in a custom drop, you always need a namespace
and a key
. This means you can't save information purely in a namespace
. A custom drop with namespace
'the_namespace', and key
'the_key' on a period, would look like this:
custom.the_namespace.the_key
In the custom drop you can either store a text or a dictionary. So you can store a text in period.custom.the_namespace.the_key
or you can store a text in period.custom.the_namespace.the_key.attribute_1
and another text in period.custom.the_namespace.the_key.attribute_2
, effectively using period.custom.the_namespace.the_key
as a dictionary. You can't combine both behaviours in a single custom drop.
Collections
Next to regular values, you can also store collections in a custom drop, this can be done by iterating over the namespace and then using the custom drop as a dictionary:
{% for item in custom.the_namespace %}
{{ item.some_property }}
{% endfor %}
To allow a user to enter information in a custom drop, it's necessary to use an input tag. Internally the entered data will always be saved as a string and interpreted based on how it's used in the template. So data entered as a currency can be interpreted as a string.
.persisted
Allows to check whether the information was added in the for loop or whether the loop exists or not. In other words, it shows/hides the subsequent iteration result of for loop.
{% stripnewlines %}
|--------
|--------
{% newline %}
{% fori company in custom.companies %}
|{% input company.name placeholder:"Company name" %}{% newline %}
{% if company.persisted %} {% comment %}all other fields will be shown depending on which the loop "exists" or not, and that is defined in the first inpit{% endcomment %}
|VAT number |{% input company.vat_numbern placeholder:"VAT number" %}{% newline %}
{% endif %}
{% endfori %}
{% endstripnewlines %}
Special attributes
A custom drop has a few special attributes, which are not regular attributes. Note, however, that within for- and foriloops, the updated_by and updated_at functions are always registered per iteration. If you have multiple custom variables in an iteration, liquid will return you the username and time when one of these custom variables are changed.
Method | Return type | Description |
---|---|---|
updated_by | UserDrop | A UserDrop for the user that last updated this custom drop |
updated_at | DateTime | The time this custom drop was last updated. |
Updated about 3 years ago