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

When an icon is displayed, it changes the value of the $icon variable in the document context

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      Copy/paste the following code (in a 2.1 syntax document):

      {{velocity}}
      #set($icon = 'XWiki')
      Variable before: $icon
      $services.icon.render('world')
      Variable after: $icon
      {{/velocity}}
      

      You obtain:

      Variable before: XWiki
      (the icon is displayed here)
      Variable after: globe
      

      The reason is that DefaultIconRenderer sets the $icon variable to compute the wiki syntax that should be generated to display an icon:
      https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-6.3-rc-1/xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/main/java/org/xwiki/icon/internal/DefaultIconRenderer.java#L126

      I believed xwiki.parseContent() was executed in an other context than the document one, but it is not.

      3 possible fixes:

      • make xwiki.parseContent() executed in its own context (could break backward compatibility)
      • create a new API to execute velocity code it a new context (or does it exists already?)
      • the hacky way (I don't like it of course), put inside "contentToParse" the following code;
        #set($__oldIconValue__xwiki_private_var = $icon)
        ## render the icon here as before
        #set($icon = $__oldIconValue__xwiki_private_var)
        

      Attachments

        Activity

          People

            gdelhumeau Guillaume Delhumeau
            gdelhumeau Guillaume Delhumeau
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: