Forum Discussion

jcracraft's avatar
7 years ago

Conditional based on rank

I'm trying to have a sub-nav with line items dependent on whether a user has the rank of administrator. I've evaluated a LiQL query that evaluates correctly on the homepage, but when you navigate to ...
  • jcracraft's avatar
    jcracraft
    7 years ago

    I found my own solution. Apparently it matters where you put the <#attempt> The LiQL query needs to be before<#attempt>. This was my solution in case anybody else has the same issue.

    <#--  LiQL query for active user  -->
      <#assign adminRole = 't:Administrator' />
      <#assign userSearch= user.id />
      <#assign queryRole= "SELECT id FROM roles WHERE users.id='${userSearch}'" />
      <#assign queryData= rest("2.0","/search?q=" + queryRole?url) />
      <#assign queryResult = queryData.data.items[0].id />
    
      <#attempt>
        <#if queryResult == adminRole >
          <#-- Adding blog to secondary nav if user is administrator   -->
          <#assign navItems = [blog, groups, training, events, faq] />
        </#if>
        <#recover>
          <#assign navItems = [groups, training, events, faq] />
      </#attempt>