Re: Freemarker Template Organization Best Practices?
Michael Cervenak Ahern <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Well there are plenty of answers to this question. Some practices I have
used on other projects (although) JSP based projects is to place the files
in a sub folder of WEB-INF. This prevents users (hackers)
from inadvertently accessing templates you do not want them to access
directly (like your header/footer). Using something like struts or stripes
in an MVC pattern your controller would then forward the request to the
template file for your page.
Another practice - and this is more stylistic - is to separate common layout
including header / footer files from your pages:
/WEB-INF/ftl/
layouts/....
pages/...
I then typically have a subfolder per page containing the layout definition
template and sub layout sections:
/WEB-INF/ftl/pages/search/
search-layout.ftl
search-lhs.ftl
search-main.ftl
search-rhs.ftl
Refactor as you go and the best practice should fall out.
Regards,
-Mike
On Tue, Jul 13, 2010 at 3:18 PM, Keith Swallow <[email protected]>wrote:
> Greetings All,
>
> I followed the instructions provided by Daniel on adding a header and
> footer to a template. (
> http://thread.gmane.org/gmane.comp.web.freemarker.user/4797) Things are
> working well (thanks Daniel!) and I was just wondering if there is a best
> practice or usage pattern that would be better than what I am doing.
>
> My idea was to organize my templates and macros where each section of the
> site has its own template path. Something like this:
>
> /templateRoot/common.ftl
> /templateRoot/myServlet/list.ftl <-- needs main.ftl for header and footer.
>
> To achieve this I overrode the requestUrlToTemplatePath method on the
> FreemarkerServlet as follows.
>
> @Override
> protected String requestUrlToTemplatePath( final HttpServletRequest request
> ) {
> final String path = super.requestUrlToTemplatePath( request );
> return this.getClass().getSimpleName() + path;
> };
>
> Is there a better way to do this (or something similar)? I have looked for
> a Freemarker Best Practices and haven't found a whole lot.
>
> Best,
>
> Keith
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user