On Thu, Aug 22, 2013 at 3:33 PM, Valdis Vītoliņš <[email protected]> wrote:
I'm trying to move all velocity macro customizations from files to the database according to http://platform.xwiki.org/xwiki/bin/view/DevGuide/SkinExtensionsTutorial
Though I can't find out syntax and execution rules (e.g. order) for parsed entries.
E.g. to implement different styles for anonymous and logged in users for XWiki.StyleSheetExtension parsed code (how Velocity can decide which is macro and whic is CSS id?):
Velocity doesn't know about CSS. Everything that looks like a Velocity macro or variable is evaluated. Of course, undefined macros and variables are printed as is so in your example below you'll get #xwikicontent after the Velocity code is evaluated, unless you have a 'xwikicontent' Velocity macro defined.
#if($isGuest) #xwikicontent { background-color: blue; } #else #xwikicontent { background-color: red; } #end
Similarly, what should be right way to show alert for XWiki.JavaScriptExtension parsed code:
alert($isGuest);
Velocity is a template language so when the Velocity code is evaluated the Velocity variables are simply substituted in the template by their values. So could get alert(false); This works because 'false' is a literal boolean value in JavaScript. But if your code was alert($xcontext.user); you could get alert(mflorea); which will throw an exception unless 'mflorea' is a JavaScript variable previously defined. Obviously you need to wrap the value in quotes. alert('$xcontext.user'); But this is not enough, because the value coming from Velocity can contain characters that are not allowed in a JavaScript string literal. So safest is to write: alert('$escapetool.javascript($xcontext.user)'); Hope this helps, Marius
Thanks! Valdis
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users