On Aug 29, 2012, at 11:26 AM, Marius Dumitru Florea <mariusdumitru.florea(a)xwiki.com>
wrote:
Sorry, wrong key combination..
On Wed, Aug 29, 2012 at 12:22 PM, Marius Dumitru Florea
<mariusdumitru.florea(a)xwiki.com> wrote:
> Hi devs,
>
> I need to have some Velocity macros in the file system because one use
> case where I need them is when the database is empty. So I put them in
> a new Velocity template file under /templates folder. I didn't want to
> add them to macros.vm because they are very specific and not used very
> often. Plus, I don't like the idea of putting all the macros in one
> single file.
It's more than that. Putting them in macros.vm make them global velocimacros, i.e.
macros registered globally in the Velocity Engine when it starts.
I then tried
to include these macros in my other template and some
wiki page using #template. It didn't work. Surprisingly, when I
attached the template with the macros to the skin it worked.
By looking at the code I noticed that #template calls
XWiki#evaluateTemplate which (if I understood correctly) registers the
Velocity macros under
* '' (global) namespace if the template is part of a skin
* template name namespace if the template is not part of the skin.
Both seem wrong:
* in the first case, once you include the template the Velocity macros
become available globally, for the entire farm, even with a different
skin
* in the second case, the Velocity macros are not visible in the
including template/wiki page
Since this cod is pretty old it's quite tricky to fix. Thomas
suggested to use instead of '' and template name the current namespace
Can you remind me what is the current namespace?
so that #template behaves like a real include (e.g.
like the include
macro).
WDYT?
Looks ok but needs a lot of testing to ensure nothing gets broken.
BTW my proposal to use the Rendering engine to parse template files should solve this
issue as well :)
Thanks
-Vincent