Forum Discussion

jmurray's avatar
jmurray
Champion
12 years ago

trying to get usernames to be colored by rank color in a module

Hi,

 

So here's what I've got so far:

internalsignin.PNG

 

The problem with this^ is that my username is green.  It should be red, because I'm an admin.  Likewise, my Community Guides should be pink, etc.  So, I want my code to ask "what rank are you?" and then color the link accordingly.  This is proving to be more difficult than I had foreseen.

 

The code that makes all of this work (above the Top Topics part) is:

<#assign ranking = rest("/users/id/${user.id}/ranking").ranking /> 
<#assign rank_name = ranking.name />
<#if rank_name == "Administrator" || rank_name == "Community Manager">
<style> .rankcolor { a:link {color: #ff0000;} a:active {color: #ff0000;} a:visited {color: #ff0000;} a:hover {color: #ff0000;} } </style>
</#if>

<#if user.anonymous == true> <u><h3>Have You Registered?</h3></u><p></p> <p style="margin:0px 0px 6px 0px;"> <center><a href="http://community.webroot.com/t5/user/userregistrationpage?dest_url=http%3A%2F%2Fcommunity.webroot.com%2Ft5%2FIndividuals-Families%2Fct-p%2Fconsumer%3Futm_campaign%3Dcommunity%26utm_medium%3Dinterstitial%26utm_source%3Dcommunity" target="_self"><img src="http://community.webroot.com/t5/image/serverpage/image-id/2374iF2D5844BB6B46F80/image-size/original?v=mpbl-1&px=-1" border="0" alt="Register Now!" title="Register Now!" align="middle" /></center></p></a> </#if> <#if user.anonymous == false> <h3>It's nice to see you again, <a href="/t5/user/viewprofilepage/user-id/${user.id}" class=rankcolor>${user.login}</a>!</h3><p> <#assign is_emp = false /> <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role> <#if role.name?? && (role.name == "Employee") || role.name?? && (role.name == "Moderator") || role.name?? && (role.name == "Administrator")> <#assign is_emp = true /> </#if> </#list> <#if is_emp = true> <br> It looks like you're a Webrooter! <br> <a href="this link goes to the employee forum">Join us on the employee forum!<br><img src="/html/assets/EmployeeForum.png" border="0" alt="Employee Forum" title="Employee Forum" align="middle" /></a> </#if> </#if>

 

You'll see there where I am trying to force the class "rankcolor" into my 'a' link.  So here's the thing about that^.  It doesn't work.  Lithium seems to override what I'm telling that link color to change to.  Firebug tells me this stuff here, from the main CSS, is forcing it to be green:

.lia-body .lia-content a, .lia-body .lia-content a:link, .lia-body .lia-content a:visited, .lia-body .lia-content a:hover, .lia-body .lia-content a:active, .lia-body .lia-content a:focus {
    color: #7A9C2C;
    text-decoration: none;
}

 

If I change .lia-stuff, it changes it everywhere.  I'd be happy to change it only for that module, but I'm not really sure how.  This may be a noobish question perhaps.

 

I'll deal with additional ranks with more ITE statements, but only once I get the link to change color for this one first.  I unfortunately don't see how to do that.  I'm missing something, and it's probably something simple.  I've tried pulling it out of the H3, and that doesn't help.  I tried adding the class to the h3, and that only turns all the words around the link red but not the link itself.  I stumbled across a "UserName" class referenced somewhere else and tried that too, hoping it was Lithium's shortcut to colorizing usernames properly, but it didn't appear so.

 

I hope all this code is helpful to people trying to do similar things.  Please give me a hand.  :)

 

(By the way, if the user is unregistered, it gives them a Register Now button instead...)

register.PNG

 

For posterity, this tkb and this tkb were really helpful to me in getting this far.

  • Hi,

     

    note that you can also use rest to get the rank color for the user and freemarker to get the user's profile page url:

     

    <#assign rank_display = rest("/users/login/${user.login}/ranking").ranking />
    <#assign rank_color = rank_display.display.color />
    <#if rank_color != "">
    	<#assign rank_color = "style=\"color:#${rank_color}\"" />
    </#if>
    
    <a class="lia-link-navigation lia-page-link lia-user-name-link" ${rank_color} target="_self" href="${user.webUi.url}">
    	${user.login}
    </a>

     

  • YuriK's avatar
    YuriK
    Khoros Expert

    Hey Jim,

     

    The Lithium selector for links is more specific and was taking precedence. Also for some reason your css formatting wasn't working.

     

    I was able to get it to work by using !important as follows:

     

    <style type="text/css"> 
    a:link.rankcolor  {color: #ff0000 !important;} 
    a:active.rankcolor  {color: #ff0000 !important;} 
    a:visited.rankcolor{color: #ff0000 !important;} 
    a:hover.rankcolor {color: #ff0000 !important;}   
    </style> 

     Hope this helps,

     

    Yuri

    • YuriK's avatar
      YuriK
      Khoros Expert

      This is probably an even better way to do it. To avoid using !important.

       

      <style type="text/css"> 
      .lia-body .lia-content a, .lia-body .lia-content a:link.rankcolor  {color: #ff0000;} 
      .lia-body .lia-content a, .lia-body .lia-content a:active.rankcolor  {color: #ff0000;} 
      .lia-body .lia-content a, .lia-body .lia-content a:visited.rankcolor{color: #ff0000;} 
      .lia-body .lia-content a, .lia-body .lia-content a:hover.rankcolor {color: #ff0000;}   
      </style> 

       

       

      • ChiaraS's avatar
        ChiaraS
        Lithium Alumni (Retired)

        Hi,

         

        note that you can also use rest to get the rank color for the user and freemarker to get the user's profile page url:

         

        <#assign rank_display = rest("/users/login/${user.login}/ranking").ranking />
        <#assign rank_color = rank_display.display.color />
        <#if rank_color != "">
        	<#assign rank_color = "style=\"color:#${rank_color}\"" />
        </#if>
        
        <a class="lia-link-navigation lia-page-link lia-user-name-link" ${rank_color} target="_self" href="${user.webUi.url}">
        	${user.login}
        </a>