Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-9027

Velocity macros defined before the call to a wiki macro are not visible in the wiki macro

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      Actually, the problem is not that macros are not visible, but that variables are visible and this feels like inconsistent behaviour.

      The idea is that we have a wiki macro defined in a wiki page, whose macro code contains a velocity macro. We want to be able to define a velocity macro before we execute this wiki macro and use it in the wiki macro.

      To reproduce, create a wiki macro in a page, with the macro id "vcontextmacro" and the content:

      {{velocity}}
      
      $myVar
      
      #myMacro()
      
      {{/velocity}}
      

      , available on current wiki (all other macro settings shouldn't matter).

      Then, in a different page, put this code:

      {{velocity}}
      #set($myVar = "my variable")
      
      #macro(myMacro)
        my macro
      #end
      {{/velocity}}
      
      {{vcontextmacro /}}
      

      This page will display the following:

      my variable
      
      #myMacro()
      

      Thus showing that the variable defined in the velocity block is available, while the macro is not.

      Moreover, if, in the page we replace the call to vcontextmacro with the actual code of the macro, it will display:

      my variable
      
      my macro
      

      .

      I should mention that I don't know if it's good or not that the macros are not visible (it would serve me for my usecase but I cannot asses whether it's a good idea in general), but what I know is that the behaviour for macros and variables should be consistent.

      Attachments

        Activity

          People

            tmortagne Thomas Mortagne
            lucaa Anca Luca
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: