SOLVED

How do I dynamically set the current year in an email and landing page?

Go to solution
Anonymous
Not applicable

How do I dynamically set the current year in an email and landing page?

How do I dynamically set the current year in an email and landing page?

Is there Marketo code that can dynamically set the current year as in copyright 2015?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I dynamically set the current year in an email and landing page?

You have to use 2 methods — JavaScript for LPs, Velocity for Emails.

 

On LPs, this snippet will do the trick:

 

<img src="" style="display:none;" onerror="this.outerHTML=new Date().getFullYear();">

 

 

Note: the above is ridiculously far from best practices for authoring JS on the browser side. It's a pretty cringey hack. BUT if you're completely unfamiliar with JS and the DOM, it lets you insert a single HTML element which replaces its own contents at runtime. No prettier ways to accomplish that, AFAIK!

 

For Velocity, I've posted the code a few times before, if you search.

View solution in original post

6 REPLIES 6
Josh_Hill13
Level 10 - Champion Alumni

Re: How do I dynamically set the current year in an email and landing page?

You could add a script to the Template or as Custom HTML.

Another way, which is commonly used, is a Folder token:

{{my.Copyright Year}}

which is changed each year. You embed this token in the Template to work.

Ross_Burck
Level 1

Re: How do I dynamically set the current year in an email and landing page?

Frank |

Here's a great thread/video that walks you through the process.  Summarily you create a top-most folder (named !Universal)  under Marketing Activities that all your programs reside in, then you set a number token on that top-most folder called copyrightYear with the current year as the number, then you insert the token - {{my.copyrightYear:default=edit me}} - where you want that year and it magically appears when the email is sent out or the landing page is rendered.  That way all you do each year is update that one token and every asset using it reflects the update!

In the html it'll look like something this:  ©{{my.copyrightYear:default=edit me}}

Thread - https://nation.marketo.com/ideas/3110#comment-15198

Video - Architecting a Robust and Scalable Marketo setup (Marketo Summit 2015) - Etumos

R-

aalvarado
Level 1

Re: How do I dynamically set the current year in an email and landing page?

Is there a way to use a similar token that will update the year when I "download HTMLs" also?

 

This is what I'm using {{my.current year:default=edit me}} and that is what appears in the download HTML.

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I dynamically set the current year in an email and landing page?


Is there a way to use a similar token that will update the year when I "download HTMLs" also?

The method I posted above will run if you open the downloaded page as well (though not sure why that matters).

 

By definition, {{my.tokens}} will only be interpolated — that is, replaced with their value on the Tokens page — when Marketo serves up the page. It’s impossible to have a {{my.token}} that gets interpolated when you simply open the HTML in your browser.

 

 

florenzoNIP
Level 2

Re: How do I dynamically set the current year in an email and landing page?

I tried out that token and it says it does not work. Is there a better way to do this on a system level instead of per camaign? 

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I dynamically set the current year in an email and landing page?

You have to use 2 methods — JavaScript for LPs, Velocity for Emails.

 

On LPs, this snippet will do the trick:

 

<img src="" style="display:none;" onerror="this.outerHTML=new Date().getFullYear();">

 

 

Note: the above is ridiculously far from best practices for authoring JS on the browser side. It's a pretty cringey hack. BUT if you're completely unfamiliar with JS and the DOM, it lets you insert a single HTML element which replaces its own contents at runtime. No prettier ways to accomplish that, AFAIK!

 

For Velocity, I've posted the code a few times before, if you search.