You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Claude Brisson <cl...@renegat.net> on 2005/09/16 08:35:09 UTC

Template naming conventions

It seems that in all the docs and samples, the choosen policy is to call
the template files foo.vm, not including in the filename any information
about the targeted mime type. But I think this is a bad practice and
I've always preferred different policies, like "foo.js.vm".

There is a related topic which is the url resolution process: by
overloading the servlet.getTemplate() method, you can for instance have
urls of the form /foo.js : getTemplace() first tries to get a foo.js and
then foo.js.vm, or the contrary).

Survey: Which convention do you use? And do you think we should change
the docs so that newcomers get good habits?

If you agree I'll create a bug report about it.

--
Claude



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Template naming conventions

Posted by Claude Brisson <cl...@renegat.net>.
On Fri, 2005-09-16 at 12:57 +0200, Christoph Reck wrote: 
> Others like the ending *.vtl ;)

Sounds better, yes.

[...]

> I believe it is up to the application designer to do recommendations
> on file naming.

I'm not sure. What I mean is: since the default behaviour is bad, why
not change it ?

The VelocityViewServlet.getTemplate() method could juste postpone ".vtl"
to the URI by default (and only handle .vtl files in its servlet-mapping
clause).

So, a request http://www.foo.com/bar.html would map :
1. to a template bar.html.vtl if found
2. to a regular html file bar.html otherwise

Beyond the first basic samples, any webapp will need such a behaviour.
So all application designers will subclass VelocityViewServlet to do it.
Why not then incorporate it ? Anyway, not before veltools 2.0 of course,
since there is a backward compatibility issue. But I'll post an issue
since I'm convinced that the "double file extension" paradigm is the
only proper way of handling template files and that it shoud definitely
be the default behaviour.

--
Claude

> > 
> > If you agree I'll create a bug report about it.
> > 
> > --
> > Claude
> 
> :) Christoph
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Template naming conventions

Posted by Christoph Reck <ap...@recks.org>.
Others like the ending *.vtl ;)

"vm" was historically interited by when taking over the original "wm"
(WebMacro -> VelocityMacro). Velocity template "vtl" seems more proper.


Claude Brisson wrote:
> It seems that in all the docs and samples, the choosen policy is to call
> the template files foo.vm, not including in the filename any information
> about the targeted mime type. But I think this is a bad practice and
> I've always preferred different policies, like "foo.js.vm".

Yes, this looks good - but beware, I've seen some systems (like mozilla
on Win) when downloading files with several dots in the name, convert
all but last dot to undescores (like filenames with version numbers).
OK, this is not a problem for Vel templates, since these are typically
rendered and not downloaded...

> 
> There is a related topic which is the url resolution process: by
> overloading the servlet.getTemplate() method, you can for instance have
> urls of the form /foo.js : getTemplace() first tries to get a foo.js and
> then foo.js.vm, or the contrary).

This is resource loader issue, which would be an application issue...

> 
> Survey: Which convention do you use? And do you think we should change
> the docs so that newcomers get good habits?

What in the docs do you mean:
- The names like foo.vm?
- The naming convention *.vm or *.vtl ?
- examples containing things like JavaScript? (are there doc examples on this?)

Please note that you would then also need things like:
   foo.js.vtl
   bar.html.vtl
   baz.css.vtl
   bax.xml.vtl
etc.

I believe it is up to the application designer to do recommendations
on file naming.

> 
> If you agree I'll create a bug report about it.
> 
> --
> Claude

:) Christoph

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org