Ludovic:
Thanks for your explanation, which was very helpful; sorry I haven't replied before
this. Looking at the source, it was clear that one directive turned on a "pre"
flag and the other didn't, but the implications of this which you explained had not
occurred to me, especially since the $xwiki methods that implement them also allowed a
flag of the same type.
However, I am already using #includeMacros, as I mentioned, so unfortunately it
doesn't solve my problem. I had the issues confused in my mind, but it now appears
that it doesn't have to do with which directive I use to include it, because it
isn't a question of whether the included content is rendered before or after
inclusion, but whether a macro definition file ever loads.
Our wiki is configured as by default up to this point - i.e. the "view" action
calls $xwiki.includeForm("$menudoc", false), which (If I understand it
correctly) effectively includes the content of $menudoc (which is XWiki.Menu in our case)
WITHOUT any interpretation.
Our copy of XWiki.Menu has been modified to use
#includeTopic("Main.FoldingMenu") (causing Main.FoldingMenu to be interpreted in
a separate context BEFORE being inserted into the including document -- correct?).
Main.FoldingMenu uses #includeMacros("Main.MenuMacro") and, after setting up the
necessary stylesheets and javascript functions, calls the one macro defined in it,
#doMenu, on $doc, where the top-level menu entry objects reside.
When the wiki is started, the #includeMacros directive apparently fails, because the name
"doMenu" is not the name of a macro definition in the context when called, so
that instead of executing the macro, Velocity simply renders it as
#doMenu(com.xpn.xwiki.api.Document@7a3a97). So the content of the menu document is being
rendered (witness the expansion of its single argument, which was $doc), but at the time
that it is, the macro definition was not in the context.
After some activity ranging from just opening Main.FoldingMenu as a regular document
(calling the "view" action on it) to opening it in the editor to actually saving
a new version of it, the macro document finally loads and the macro executes. Friday
(while I was out, naturally), none of that worked for the people who were here and they
replaced it with a hard-coded list.
First, it appears that I need to check the logs to see whether there was some failure in
the loading of the macro document and troubleshoot that. It may be that a permission
problem exists, though I doubt that this could have been the problem - first, every time
the problem was corrected, the person who seems to have fixed the problem also experienced
it first, and second, the history of the menu document shows that they apparently tried
some manipulations of this sort without effect. Neither of these discounts the idea, of
course, so neither will I, but I'm not hopeful.
Meanwhile, has anyone any ideas? I will, of course, try adding the macro definition to
macros.vm, but I suspect that this would only decrease the incidence of the problem rather
than eliminating it. It happens seldom enough that it's hard to reproduce as it is,
and can't be done at all without restarting the wiki, which is getting to be fairly
popular.
For one thing, is there a programmatic way to know when an #include directive fails, or do
I have to examine the logs? I wouldn't argue for muddying a template language with
such a feature, certainly, but if there's some background magic available to
administrative users for troubleshooting purposes, it could be useful. I think
there's probably still a little too much that needs server administrator access to
troubleshoot.
brain[sic]
-----Original Message-----
From: Ludovic Dubost [mailto:ludovic@xwiki.com]
Sent: Sunday, April 09, 2006 8:48 AM
To: xwiki-users(a)objectweb.org
Subject: Re: [xwiki-users] #include<what?>
Hi,
#includeTopic -> includes and executes any code in the context of the
INCLUDED document (variables are the one from the included document) #includeForm ->
includes and executres any code in the context of the
INCLUDING document (variables are the one from the including document) #includeMacros
-> used to embed macros to solve the problem that you are
having
Another way to solve it is to put your macro in /templates/macros.vm and
restart XWiki. This will make your macro global. It's actually better
for performance.
Ludovic
THOMAS, BRIAN M (SBCSI) a écrit :
The various kinds of #include directives have always
puzzled me, but
now I think I may have a serious need to understand them.
I have seen that some of them are implemented by methods on $xwiki
(includeForm, includeTopic, in two incarnations each - with or without
rendering, I assume), but I have no understanding of why they are all
different. Add in the parse directives and XWiki methods and I am
completely confused.
Can anyone give me a synopsis of what these are all about? I
understand this much: that Velocity directives are read once at parse
time, whereas methods can be invoked multiple times in a loop.
The problem I need to solve, however, may be a Velocity problem or a
caching problem. A menu is called from the left-side navigation menu
XWiki.Menu. I have included it via #includeTopic, and it use
#includeMacros to bring in a macro that reads a document with a list
of objects describing menu items, with a menu label, an href, and a
long description. If the href field is a complete URL, it's output as
a plain link; if it's a local Wiki document, it's output with XWiki's
bracket syntax and its place is held in the menu as a navigational
aid. If it is also in the Web reserved for such documents, it's a
submenu, and the menu macro is called again (thanks to the earlier
thread, I did use a copy of the argument, which is call-by-reference,
and saved headaches).
All of this works just fine except the first time it's called after
the server starts. Instead of the menu text, all I see is the
invocation of the macro. Viewing the menu document directly (as I did
when I sought to debug it) fixes the problem for all until the next
reboot.
So what is this? I read some discussion on the velocity-user mailing
list about when and how macro templates are loaded, but didn't
understand it well; in addition, there is all this confusion about
when to include in what way.
brain[sic]
----------------------------------------------------------------------
--
--
You receive this message as a subscriber of the
xwiki-users(a)objectweb.org mailing list. To unsubscribe:
mailto:xwiki-users-unsubscribe@objectweb.org
For general help: mailto:sympa@objectweb.org?subject=help
ObjectWeb mailing lists service home page:
http://www.objectweb.org/wws
--
Ludovic Dubost
XPertNet:
http://www.xpertnet.fr/
Blog:
http://www.ludovic.org/blog/
XWiki:
http://www.xwiki.com
Skype: ldubost AIM: nvludo Yahoo: ludovic