With this example, I want to show a copyright notice with the year automatically adjusted. Although this is a follow on from the Push Footer to bottom of viewport tutorial, you can apply this technique to any equivalent scenario.
- We start with a page that contains the normal ingredients:
- Next, place the Date and Time widget into our document by right-clicking App and choosing Data and Date and Time
- Choose the widget and give it an ID and change the Interval to Days
- Click the footer to select, double-click to edit, position the cursor after 2019 and click the lightning symbol.
- Choose datatime and select the formatting button.
- Right-click varDate.datetime, Date and Time and Format Date
- Format for the year
NOTE: If you only want the year, i.e. not a data range, then you can remove the original 2019 and the year will automatically update. If you do want the date range, then continue.
- We need to compare the current year with the initial year so that we do not double up, e.g. 2019 - 2019. Right-click Format Date and choose Operation
- Select the equals operator and 2019 as the value
- Right-click equals operator and choose Operation
- Choose the ternary operator (?) and give the true part a space (spacebar)
- Because the ternary operator is at a wrong level, we need to drag it under the ternary operator until we see a tick, upon which let go and it will find itself on the correct level.
The result is
- Click the ternary operator and select Operation
- Choose the else part ( of the operator
- For the value, we use the lightning bolt
and select datetime:
- When the equation is false, we need to have the current year showing after a dash (’ - '). This is done as per following.
- As before, the operation is at a wrong level. We need to drag it to the ternary operator similar to what was done in step 12. The result will look like
- To format the date, right-click varDate.datetime, choose Date and Time and Format Date
- Format the date as a year by choosing Formatting enter the format and choose Select.
- Click Select and save your work.
- This is the end result after saving your work.
- To test your work change the years in the following code:
<p class="text-secondary text-center small mb-0 p-1">© Copyright 2019 {{varDate.datetime.formatDate("yyyy") == 2019 ? " " : (' - ' + varDate.datetime.formatDate("yyyy"))}}. All Rights Reserved.</p>
Changing these to 2012 will show the following result
Community Page
Last updated:
Last updated: