Calendar Transformations
JSON rules that change, recolor or remove date elements while a calendar project is being built. This is how one page design produces twelve months.
JSON rules that change, recolor or remove date elements while a calendar project is being built. This is how one page design produces twelve different months.
Overview
Calendar transformations live in a text area on the design page in admin. The value is a JSON array. Each rule in the array has a selector, which decides which elements it applies to, and an action, which decides what happens to them.
Rules run when the project is built, so nothing you see in the admin design tool reflects them. Always check the result in customer mode or in the generated PDF.
How to add transformations
Go to Admin > Products > Designs and open the design.
Find the Calendar Transformations field.
Paste a JSON array. If you are combining several rule sets, merge them into one array rather than pasting several arrays.
Save, then create a test project and check the months the rules affect.
Selectors
A selector is a JSON object and must contain at least one of these keys. When several keys are present, all of them must match.
series
Elements bound to this date series
name
Elements with this element name
tag
Elements whose date carries this tag, set with tag in the definition
year
Elements whose date falls in this year (number)
month
Elements whose date falls in this month (number, 1 to 12)
weekday
Elements whose date falls on this weekday (MO to SU)
day
Elements whose date falls on this day of the month (number)
week
Elements whose date falls in this week number of the year (number)
calendar
Elements whose date has a caption in a calendar
The calendar selector takes one of these values:
any- any calendar used in the project has a caption for this dateuser- a customer-provided calendar has a caption for this datewebsite- a calendar created under /calendars in admin has a caption for this datewebsite:<code>, for examplewebsite:holidays- the website calendar with that code has a caption for this date
Actions
delete
No
Removes the element from the built page
set-color
Yes, a hex color
Recolors the element
set-text
Yes, the replacement text
Replaces the text content
set-image-src
Yes, an image reference
Swaps the image
Recipes
Grey the days from the previous and next month
The days outside the displayed month are tagged out-of-range by the month-grid sequence in the definition. One rule styles all of them.
Replace set-color with delete to hide them entirely. Remove the rule altogether to print them in the same style as the rest of the month.
Red Sundays and holidays
A logo on December only
Name the logo element brand-logo in the design, then delete it on the other eleven months. One rule per month:
Continue through month 11. There is no "all months except" selector, so every month that should not show the element needs its own rule. The complete eleven-rule version is in Example Calendar Templates.
Alternating artwork on odd and even months
Put both versions of the artwork on the same page, named art-odd and art-even, then delete the one that does not apply. Twelve rules, one per month.
This keeps the calendar in January-to-December order. Splitting the loop into odd and even date sequences also works, but it outputs all the odd months first and then all the even months, which is almost never what a calendar should do.
Custom month names
Only use this when you want something other than the standard month name, such as an abbreviation or upper case. Standard month names are translated automatically. See Month Names and Translations.
A different background per season
Combined example
Red Sundays, and no element at all on Friday the 13th.
Tips
A transformation can only find an element by name if the element has a name. Set it in the Admin panel on the element before writing rules.
Rules that select on
namealone apply to every month. Addmonthto scope them.If a transformation does nothing, check the element name for a typo and check that the element is actually bound to a date in the Dates panel. Elements with no date binding are not matched by date selectors.
Ready-made rule sets for all of the above are in Example Calendar Templates.