One thing to keep in mind: client (browser) caches don't know about
Velocity.
This means that if you write different CSS rules depending on some
variables, like is guest or authenticated users, then when a user opens the
wiki and authenticates, something "strange" will happen. The browser will
first fetch the CSS file, which will contain the rules for the guest user.
This CSS is stored in the browser's cache, and it won't be re-fetched
unless the user forces a cache refresh. So after loggin in, the user will
continue to see the guest UI.
This means that a feature intended for improving the performance now breaks
your intended behavior. One solution is to disable caches (which is
possible for skin extensions, but not for filesystem files), but this
impacts the performance.
Another solution is to put different parameters in the URL used to fetch
the CSS or JS, for example:
$xwiki.ssx.use('Some.Document', {'isGuest': $isGuest})
$xwiki.jsx.use('Some.Document', {'user': $xcontext.userReference,
'hasAdmin': $hasAdmin})
Yet another solution (which only works for JS, not for CSS) is to store the
variable data in the HTML, and the JS will fetch it from there. There are
already plenty of variables stored in <meta> elements, such as the current
document coordinates and the CSRF prevention token, and some are defined as
JS variables, such as XWiki.hasEdit. This is the preferred way of passing
information to JS scripts, since it allows the extensions to be cached,
while still being aware of the current context. The downside is that the
<meta> fields can't be easily altered from the document content, they have
to be modified in a skin file or in the global administration (there's a
special field for modifying the metadata).
On Thu, Aug 22, 2013 at 10:22 AM, Marius Dumitru Florea <
mariusdumitru.florea(a)xwiki.com> wrote:
Thanks. One remark: we're moving away from
'XWiki.XWikiGuest'. The
best way to check for guest user is to check for null user reference.
See
http://www.xwiki.org/xwiki/bin/view/ReleaseNotes/ReleaseNotesXWiki50#HXWiki…
. So:
#if (!$xcontext.userReference)
Guest user!
#end
Hope this helps,
Marius
On Thu, Aug 22, 2013 at 4:51 PM, Valdis Vītoliņš <valdis.vitolins(a)odo.lv>
wrote:
Thanks Clemens and Marius!
I updated
http://platform.xwiki.org/xwiki/bin/view/DevGuide/SkinExtensionsTutorial#HH…
with additional notes.
Valdis
> Hi Valdis,
>
> it seems in the StyleSheetExtensions / JavaScriptExtensions only the
"basic" variables are defined, like $doc, $request or $xcontext
>
> The $isGuest is a "derived" variable; you can find the definition in
/templates/xwikivars.vm
>
> I am not sure if there is a better way, but at least you can get the
code
working by copy & paste the definition for the variables you need from
the xwikivars.vm to the corresponding objects
>
> hope this helps,
> Clemens
>
> > 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?):
#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);
Thanks!
Valdis
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users