Quantcast

Question about gtpl and dateFormat

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Question about gtpl and dateFormat

A_Grails_User
Hello,

I have a small EmailerService and I'm using *.gtpl files for processing the information. Now I have the case that I need to print out a date, to be more precisely a nice date. The use of ${dateCreated} is not what I want because I get the full date string, as expected. I need a way to print out a nice, formatted date within the template. What is the best way to get a nice date here? Is there a way of using <g:formatDate...> in the template somehow? Is there any other fancy trick to do so? What would you recommend?

Thanks in advance...
AGU
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Question about gtpl and dateFormat

Christian Laakmann
Hey,

I don't know, whether it's possible to use the tags in a template. However, you could add a new Method to Date via the EMC which uses DateFormatter to return a formatted String:

Date.metaClass.format { pattern -> .... }

${dateCreated.format('dd.mm.yyyy')}

Cheers
Christian

A_Grails_User wrote
Hello,

I have a small EmailerService and I'm using *.gtpl files for processing the information. Now I have the case that I need to print out a date, to be more precisely a nice date. The use of ${dateCreated} is not what I want because I get the full date string, as expected. I need a way to print out a nice, formatted date within the template. What is the best way to get a nice date here? Is there a way of using <g:formatDate...> in the template somehow? Is there any other fancy trick to do so? What would you recommend?

Thanks in advance...
AGU
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Question about gtpl and dateFormat

A_Grails_User
Ok, sounds good. But where do I put this? In the Domain class, Controller, Service?

Greets
AGU


Christian Laakmann wrote
Hey,

I don't know, whether it's possible to use the tags in a template. However, you could add a new Method to Date via the EMC which uses DateFormatter to return a formatted String:

Date.metaClass.format { pattern -> .... }

${dateCreated.format('dd.mm.yyyy')}

Cheers
Christian

A_Grails_User wrote
Hello,

I have a small EmailerService and I'm using *.gtpl files for processing the information. Now I have the case that I need to print out a date, to be more precisely a nice date. The use of ${dateCreated} is not what I want because I get the full date string, as expected. I need a way to print out a nice, formatted date within the template. What is the best way to get a nice date here? Is there a way of using <g:formatDate...> in the template somehow? Is there any other fancy trick to do so? What would you recommend?

Thanks in advance...
AGU
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Question about gtpl and dateFormat

Christian Laakmann
The Date.metaClass....-Part has to be put into the boostrap.groovy-init-Closure, I believe...

Cheers

A_Grails_User wrote
Ok, sounds good. But where do I put this? In the Domain class, Controller, Service?

Greets
AGU


Christian Laakmann wrote
Hey,

I don't know, whether it's possible to use the tags in a template. However, you could add a new Method to Date via the EMC which uses DateFormatter to return a formatted String:

Date.metaClass.format { pattern -> .... }

${dateCreated.format('dd.mm.yyyy')}

Cheers
Christian

A_Grails_User wrote
Hello,

I have a small EmailerService and I'm using *.gtpl files for processing the information. Now I have the case that I need to print out a date, to be more precisely a nice date. The use of ${dateCreated} is not what I want because I get the full date string, as expected. I need a way to print out a nice, formatted date within the template. What is the best way to get a nice date here? Is there a way of using <g:formatDate...> in the template somehow? Is there any other fancy trick to do so? What would you recommend?

Thanks in advance...
AGU
Loading...