Need help for custom buttons in XWiki

Hello everyone,

We want to create our own button in XWiki, which includes a link when the button is clicked, the button text and also the alignment of the button. For this we have the following velocity-code.

{{velocity}}
#set($buttonLink = $wikimacro.parameters.buttonLink)
#set($buttonText = $wikimacro.parameters.buttonText)
#set($buttonIcon = $wikimacro.parameters.buttonIcon)
#set($buttonAusrichtung = $wikimacro.parameters.buttonAusrichtung)

#if ("$!buttonLink" == '')
  #if ($hasEdit)
  #end
#else
  #set($discard = $xwiki.ssx.use('XWiki.Code.LRA-OA.Makros.Button.WebHome'))
  #if($buttonLink.toLowerCase().startsWith('www.'))
    #set($buttonLink = "https://${buttonLink}")
  #end
  #if($buttonLink.toLowerCase().startsWith('http') && !$buttonLink.toLowerCase().contains('.int'))
    #set($target = '_blank')
    #set($href = $buttonLink)
  #else
    #set($target = '_self')
    #set($href = $buttonLink)
  #end 

  #if("$!buttonAusrichtung" == 'rechts')
    #set($alignmentClass = "button-container-right")
  #elseif("$!buttonAusrichtung" == 'mittig')
    #set($alignmentClass = "button-container-center")
  #else
    #set($alignmentClass = "button-container-left")
  #end
  
{{html wiki="false"}}
  <div class="${alignmentClass}">
    <a class="lraoa-button" href="${href}" target="${target}">
      <span class="buttonFont">&nbsp;&nbsp;${buttonText}</span>
    </a>
  </div>
{{/html}}
#end
{{/velocity}}

So far it works quite well, but we always have an empty line in front of the button. We have already looked at CSS, but have not found a solution. Thanks for a quick tip!

Hi.

Try deleting the empty line in your code at this point:

  #end
  #if("$!buttonAusrichtung" == 'rechts')

This works for me.

Unfortunaltely this is not the solution. If I delete the empty line the button will disappear and a error appears:

Das Makro [html] konnte nicht ausgeführt werden. Grund: [When using HTML content inline, you can only use inline HTML content. Block HTML content (such as tables) cannot be displayed. Try leaving an empty line before and after the macro.]. Klicke auf diese Nachricht, um Details zu erfahren.

If I change the inline mode from yes to no / no to yes nothing happens.

Don’t remove all empty lines in the velocity code. There must be an empty line before the html macro.

That´s it – you safed my evening. Thanks so much.