Re: how to pass value from code to page template
S Ahmed <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <CAG2rwuPBKnVbd+TQveehFy-YND1D2ALOQ7MEVriKfm9E_gms=A@mail.gmail.com> |
Also, how do I check for not null and not empty? <#if title??> </#if> that checks for null only, what if I want to know if it is an empty string? ie.. "" Is it possible to have an object as a parameter in a macro? like a something like user? <@macro page user> where user has: user.name user.age ? On Thu, May 10, 2012 at 11:54 PM, S Ahmed <[email protected]> wrote: > But do I have to pass in the variable somehow? > > <@p.master title=${title}> > > Or does the macro just know that that variable exists? > > > On Thu, May 10, 2012 at 2:32 AM, Takács János <[email protected]> wrote: > >> your controller should look something like this: >> >> @Controller >> @Scope("request") >> public class IndexController { >> @RequestMapping(value="/index",method=RequestMethod.GET) >> public ModelAndView html(){ >> ModelAndView mav = new ModelAndView(); >> mav.setViewName( "index.ftl"); >> // this is how you pass a value from java to freemarker: >> mav.addObject( "title","Index Page"); >> return mav; >> } >> } >> >> In your template, ${title} will have the value "Index Page", you can >> use it included templates as well as in index.ftl. >> >> page.ftl: >> >> <#macro page> >> <#if ! title??> >> <#assign title="Default Title"/> >> </#if> >> <html> >> <title>${title}</title> >> </html> >> <body> >> .. >> <#nested> >> </body> >> </#macro> >> >> >> On Thu, May 10, 2012 at 6:20 AM, S Ahmed <[email protected]> wrote: >> > I have a page template that I use for all my pages like: >> > >> > <#macro page title="soem title"> >> > <html> >> > <title>${title}</title> >> > </html> >> > <body> >> > .. >> > <#nested> >> > >> > </body> >> > >> > </#macro> >> > >> > Then in my page I am doing: >> > >> > <#import "/page.ftl" as p> >> > >> > <@p.page title="some title"> >> > >> > ... >> > >> > >> > What if I wanted to get the title from my java code, and pass it down, >> is >> > that possible? >> > >> > I'm using spring, and my view gets the ModelAndView values, can I set it >> > from the server side and pass it as a parameter for title? >> > >> > >> ------------------------------------------------------------------------------ >> > Live Security Virtual Conference >> > Exclusive live event will cover all the ways today's security and >> > threat landscape has changed and how IT managers can respond. >> Discussions >> > will include endpoint security, mobile security and the latest in >> malware >> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> > _______________________________________________ >> > FreeMarker-user mailing list >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/freemarker-user >> > >> >> >> >> -- >> >> Takács János >> >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> _______________________________________________ >> FreeMarker-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/freemarker-user >> > > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ FreeMarker-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freemarker-user