[xwiki-users] Problem with velocity code structuring macro invocation and variables
I'm working with several forms and struggle with Velocity code organisation. 1. I'd like to put the same code for e.g. regexp form validation in one page and just include it from other (ClassSheet) pages. Following http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with +validation+and+tooltips valdidation works fine, when #macro(showallerrors) macro is included in ClassSheet page, though it doesn't work, when macro in ClassSheet is included from other file (e.g. putting macro in VelocityScripts page and writing in ClassSheet: {{include reference="VelocityScripts"/}} or {{include document...) It works though, if macro is put in ../xwiki/templates/macros.vm file. 2. As velocity cannot use passing variables by reference, I'd like to create own "global" velocity variable similar to $isGuest, $hasComment, $hasAdmin, etc. I tried to set this in xwikivars.vm, but it didn't work. Any suggestions are welcome. Thanks! Valdis
1. I'd like to put the same code for e.g. regexp form validation in one page and just include it from other (ClassSheet) pages. Following http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with +validation+and+tooltips valdidation works fine, when #macro(showallerrors) macro is included in ClassSheet page, though it doesn't work, when macro in ClassSheet is included from other file (e.g. putting macro in VelocityScripts page and writing in ClassSheet: {{include reference="VelocityScripts"/}} or {{include document...) It works though, if macro is put in ../xwiki/templates/macros.vm file. Found it out myself. Trick was, that include section should be before velocity in ClassSheet. E.g. {{include reference="VelocityScripts"/}} {{velocity}} ...
2. As velocity cannot use passing variables by reference, I'd like to create own "global" velocity variable similar to $isGuest, $hasComment, $hasAdmin, etc. I tried to set this in xwikivars.vm, but it didn't work. Found that I can set value in cookie with Groovy: {{groovy}} import javax.servlet.http.* Cookie mycookie = new Cookie("mycookie","myvalue") mycookie.setPath("/") mycookie.setMaxAge(-1) xcontext.getContext().getResponse().addCookie(mycookie) {{/groovy}}
and then I can get it as global value in xwikivars.vm #set($myvalue=$xwiki.getUserPreferenceFromCookie('mycookie')) And then I can get $myvalue from any other page. Valdis
participants (1)
-
Valdis Vītoliņš