Hi All, I’m Florian!
I’ve been learning to script with velocity and read / learned a lot in the docs and examples! (It’s great!)
One thing I haven’t been able to grasp is – I’m guessing – the context in which a script runs. I have three examples and as far as I can tell they all have the context in common (might be wrong of course!):
-
I’d like to show a page footer (uiextension “org.xwiki.platform.template.contentFooter”) depending on the value a user has set in his user profile (via a custom class I’ve created). The executed content is:
## Get the user viewing the page #set ( $MyUser = $xcontext.user ) #set ( $MySettingsClass = "Main.System.UiExtensions.AdditionalUserSettings" ) ## Check if on the user profile an object of the class has the property set to "yes" #if ( $MyUser.getObjects($MySettingsClass)[0].PrevNextFooter == "Yes" ) {{include reference="Main.System.UiExtensions.Snippets.PrevNext" #end /}}
This doesn’t work as
$xcontext.user
seems to always return the author of the page containing the object (and code) for the uiextension.=> How can I get the user currently logged in in order the read the object of type “Main.System.UiExtensions.AdditionalUserSettings” on his user page?
Thank you very much!
Edit:
- Example 2. Keyboard shortcuts in certain contexts and
- Example 3. $doc.sace() the current doc from an included script
have been split out to separate post.