Issue with javascript expressions in edge templates


#1

I’m trying to display the current year on my email edge template. I have this © {{ (new Date()).getFullYear() }} {{ appName }} in my email edge template but I get InvalidExpressionException: E_INVALID_EXPRESSION: Invalid expression < (new Date()).getFullYear() >

How do I fix this?


#2

Why not simply say new Date().getFullYear(). I don’t see any need of wrapping new Date() inside braces


#3

That’s how I wrote it initially but I wrapped new Date() in braces when I got E_INVALID_EXPRESSION: Invalid expression < new Date().getFullYear() >


#4

Why can’t edge interpret new Date().getFullYear()?


#5

@virk I’ve still not been able to get edge to render new Date().getFullYear(). I still get E_INVALID_EXPRESSION: Invalid expression < new Date().getFullYear() >. Any idea why this happening and a way around it?


#6

As far as i know i dont think you can write “any” js code inside {{}}. (@virk could correct me if i’m wrong about it) .
As an alternative what you can do is :

  • Just pass the current year as data to the email template and then use {{currentYear}} inside the template
  • Create a view global (you can read more about it here Adonis View Globals)

#7

Works fine. Thanks