{% Now %} Macro Not Displaying Current Date and Time in Form Field in Xperience by Kentico 29.3.0
Hello Kentico Community,
I am encountering an issue with the {% Now %}
macro in Xperience by Kentico version 29.3.0. I am trying to display the current date and time in a form field when the form is rendered. However, instead of showing the current date and time, the {% Now %}
macro is being displayed as a literal string in the form field, like this: {% Now %}
.
Steps I have taken:
- Created a Text field in Form Builder.
- Set the Default Value of the field to
{% Now %}
. - Ensured the form is published and cached properly.
- Tried clearing the cache and testing again.
Issue:
- The
{% Now %}
macro does not resolve to the current date and time. Instead, it shows{% Now %}
as plain text when the form is rendered. - I have tested with other macros (like
{% DateTime.Now %}
), but the issue persists.
Questions:
- Is there any configuration needed in Xperience by Kentico 29.3.0 to enable the processing of macros in form fields?
- Is the
{% Now %}
macro supported in this context for form fields, or is there a different macro that should be used to display the current date and time?
Any assistance or suggestions would be greatly appreciated!
Thank you
Answers
As per documentation:
Macro expressions | Xperience by Kentico Documentation
In the current version of Xperience by Kentico, macro expressions are usable in:
- the source code of Email templates
- the Modules application when defining default values for the editing forms of object types
They aren't widely used or available in other areas I'm afraid. Instead, you may need to use the Form Widget Customizations to detect your "time" field and set a value in them as it renders.
Try using the below to register a FormFieldRenderingConfiguration.GetConfiguration.Execute, and in it check for your field (either by a specific TYPE of field or actual field name) and then in there you should be able to set the default value dynamically to the time.
https://docs.kentico.com/developers-and-admins/development/builders/form-builder/form-widget-customization#add-contextual-markup-to-form-fields
Hello Team,
Could you please give practical example of below usecase?
In the current version of Xperience by Kentico, macro expressions are usable in:
- the source code of Email templates
- the Modules application when defining default values for the editing forms of object types
Thank you
Trevor's answer is correct and there are examples in the documentation.
The Kentico Community Portal has a newsletter and you can sign up for. Since the code base for the Kentico Community Portal is open-source you can view the source code for that email template as an example of macro usage.
It's also worth noting that we are planning to release a native visual Email Builder in our February Refresh and potentially some improvements to the Form Builder later this year.
To answer this question, you have to login first.