Different link color depending on where a link leads to

Is it possible to create a macro in the on-demand-version of Confluence which evaluates the destination of a link (in my case, a specific sub-space) and assigns a specific color to it accordingly?

2 answers

1 accepted

This widget could not be displayed.

I don't know about on-demand or macros but in the end you will have to do it with CSS.

For this you can work with the href attribute. The following would make a link green if it goes to a URL starting with /your-sub-space/:

a[href^="/your-sub-space/"] {
color: green;
}

Thanks a lot, Steffen, this is really helpful!

This widget could not be displayed.

Hello Aline,

You can create user macro, for that you insert URL (or space key) and Link text. And then via IF set color of link.Something like that:

## @param Key:title=Space key|type=enum|enumValues=KEY1,KEY2,KEY3|desc=URL of space
## @param LinkText:title=Link text|type=string|desc=Text for showed link

#set($color="orange")

#if ($paramKey == "KEY1" )
  #set ($color="#d04437")
#end
#if ($paramKey == "KEY2" )
  #set ($color="#ddd")
#end

<a href="yourwiki.com/display/$paramKey" style="color:$color !important;">$paramLinkText</a>

Result will be that you will have a link with colors which are defined in section if.

But you have to update it manually when somebody create a new space. The first set of color virable is default set (when you insert a key, which isnt in IF rules).

Thank you very much, Aleš!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Tuesday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

107 views 12 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you