Forum Discussion

ethanede's avatar
ethanede
Helper
7 years ago

Translate Freemarker to LiQL query?

Hello all,

First time poster, new to Lithium, this is probably pretty basic, please be gentle. I did some searching but couldn't find anything directly addressing this question.

Is it possible to convert this Freemarker to a LiQL query to see the specified data? 

${(page.context.user.get("profile.agent_id"))!""}

 

  • ethanede

    If the page is associated with a user, then "context.user" returns a user context object, otherwise returns null.

    ${page.context.user.id}


    You can chain calls on the user object from this method. We can use this in MyProfilePage (only when an admin is editing another user's profile.) and ViewProfilePage on viewign other's profile information.

    <#assign page_user_id = page.context.user.id />
    <#assign custom-profile-field = profile.agent_id />

    Using V1:

    <#if page_user_id??>
      <#assign allowed=rest("/users/id/${page_user_id?c}/profiles/name/${custom-profile-field}/allowed").value />
      <#if allowed?trim == "true">
          <#assign value = rest("/users/id/${page_user_id}/profiles/name/${custom-profile-field}").value />
          <span>${value?string}</span>
      </#if>
    </#if>

    Using V2:

    Select * from users where id='${page_user_id?c}'

6 Replies

  • ethanede-

    Welcome to lithium community.

    The below method might be used on profile page which is just getting agent_id from the user profile. This is not any LIQL query.  You can be used this method on any custom component which is added on the profile page and can see the result.

    ${(page.context.user.get("profile.agent_id"))!""}

     If you want to learn more about the LIQL follow below documentation. https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv2

  • ethanede The question is, what information do you actually need?

    Generally the profile information of the currently logged in user could be fetched from the API by utilizing the FreeMarker "user" context object, which is not only available on the profile page, but everywhere, there you'll have the user.id or user.login from which you could build the API query needed. But if you want to do something specific with the agent_id this might not work...

  • ethanede's avatar
    ethanede
    Helper
    7 years ago

    Thank you for your response.

    I was simply trying to display the user ID.  The question was how to access that same information using a LiQL query as I was not able to see the agent_id in the returned json string for the LiQL query, so didn't understand from where it was pulling this data.

  • luk's avatar
    luk
    Boss
    7 years ago

    ethanede this "agent_id" field is not something I have encountered for a user object yet, so it could be possible that this is a custom "metadata" field for users in your community and therefore not returned by API v2, but that's just a guess in the dark. Would need more information on what this ID is (where is it coming from?)...

  • ethanede

    If the page is associated with a user, then "context.user" returns a user context object, otherwise returns null.

    ${page.context.user.id}


    You can chain calls on the user object from this method. We can use this in MyProfilePage (only when an admin is editing another user's profile.) and ViewProfilePage on viewign other's profile information.

    <#assign page_user_id = page.context.user.id />
    <#assign custom-profile-field = profile.agent_id />

    Using V1:

    <#if page_user_id??>
      <#assign allowed=rest("/users/id/${page_user_id?c}/profiles/name/${custom-profile-field}/allowed").value />
      <#if allowed?trim == "true">
          <#assign value = rest("/users/id/${page_user_id}/profiles/name/${custom-profile-field}").value />
          <span>${value?string}</span>
      </#if>
    </#if>

    Using V2:

    Select * from users where id='${page_user_id?c}'