If needed, we can extend the Add current year snippet to also be editable
In the Add current year snippet we looked at automatically adding the current year to a Design System. Sometimes, however, you may want to make this editable - for example if the email campaign is being set up (and exported) in December but mailed in January.
In that case, using a combination of the checkbox button and rules, we can make the current year automatic, unless you want to manually change it.
First, we need a checkbox so we can control whether the code is automated or not:
<editable name="copyright" label="Copyright statement"> <field type="checkbox" name="manual" label="Use manual date" default="false"> </field> </editable>
Then we can add a field that lets editors add manual content. If we put this inside the field tags for the checkbox, this field will only show when the checkbox is set to "on".
<editable name="copyright" label="Copyright statement"> <field type="checkbox" name="manual" label="Use manual date" default="false"> <field type="text" name="content" label="Content" default="Copyright → BrandName 2016. All rights reserved"></field> </field> </editable>
Lastly, we can then add a couple of content tags, and use rules to decide which content should show when the checkbox is set to on or off:
<content replace="Copyright → BrandName {{ 'now' | date: '%Y' }}. All rights reserved" rule="{% hide_if manual %}"></content> <content replace="{{content}}" rule="{% show_if manual %}"></content>
<editable name="copyright" label="Copyright statement">
<field type="checkbox" name="manual" label="Use manual date" default="false">
<field type="text" name="content" label="Content" default="Copyright © BrandName 2016. All rights reserved"></field>
</field>
<content replace="Copyright © BrandName {{ 'now' | date: '%Y' }}. All rights reserved" rule="{% hide_if manual %}"></content>
<content replace="{{content}}" rule="{% show_if manual %}"></content>
</editable>