Hi, is it possible for me to create something like currentYear variable and use it everywhere.
in meta title and component texts i want to use something like this.
(xxx 2025 xxx)
Hi, is it possible for me to create something like currentYear variable and use it everywhere.
in meta title and component texts i want to use something like this.
(xxx 2025 xxx)
Hi @Ischafak,
In Builder.io, you indeed have the capability to use dynamic data like the current year, accessed through JavaScript or custom fields.
Here’s an overview of how you can implement this:
Creating a Custom Field:
currentYear
.Accessing in Integration Code:
// Access custom field data
const pageContent = await builder.get('page', { /* query parameters */ }).toPromise();
const currentYear = pageContent?.data?.currentYear; // Assuming 'title' is the field containing the year
Using JavaScript in Custom Code within Content:
const currentYear = new Date().getFullYear();
builder.set('currentYear', currentYear);
Binding Current Year in Content:
context
object to bind the value within your content: The current year is {{context.builderContent.data.currentYear}}
Hope this helps!
Thanks,