Forum Discussion

dkytasaari's avatar
8 years ago

Need custom component to display user's location in Profile Hero

I want to display a user's location in the Profile Hero.  I don't see where there is a stock component to display this information, which means I need to create a custom component.  I cannot find an example of anything here, or in the KB that would be a good example to work from.  I suspect I need something like this:

 

<#assign userLOC=rest( "2.0", "/search?q=" + "SELECT location from users where id = (ID NUM of PROFILE I AM VIEWING)  />
<div>
$userLOC
</div>

What do I need to finish that WHERE clause?  Can anyone point me to a repository of examples?

 

Regards,

Dennis

  • VikasB's avatar
    VikasB
    8 years ago

    Hi dkytasaari  You are missing ending quote(") in your query.

    Here is updated one

    <#assign userLOC= rest("2.0","/search?q=" + "SELECT login from users where id='${page.context.user.id}'"?url).data.items[0] />
    <div>
        ${userLOC.login}
    </div>

    Also, I do not think so there is any location field in API.  

     

  • dkytasaari-

     

     ${page.context.user.id} is a context object which will return you the id of user profile you will be viewing. 

     

    <#assign userLOC=rest( "2.0", "/search?q=" + "SELECT location from users where id = '${page.context.user.id}').data.items[0]  />

     

    <div>
    ${userLOC.location}
    </div>

     Also, you can check if ${userLOC} is blank or not by adding if else condition.

    • dkytasaari's avatar
      dkytasaari
      Ace

      TariqHussain

       

      i've tried this:

       

      <#assign userLOC=rest( "2.0", "/search?q=" + "SELECT location from users where id = '${page.context.user.id}').data.items[0] />
      
      <div>
          ${userLOC.location}
      </div>

      The Preview parser throws an error, I cannot resolve:

      Freemarker template 'preview' parsing failed:
      ParseException:Syntax error in template "preview" in line 6, column 0:
      Lexical error: encountered <EOF> after "\"SELECT location from users where id = \'${page.context.user.id}\').data.items[0] />\n\n<div>\n    ${userLOC.location}\n</div>\n".

      Line 6 is the blank line at the bottom.  If I remove line 6, then the error moves to end of line 5.  Something is wrong, but I don't have enough experience yet to know the ins and outs of Freemarker syntax.  Is there something obvious here I am overlooking?

       

      It also seems odd that there is a quote before the SELECT, but there isn't a closing quote for the statement.  I tried inserting one in a couple of different places, but that just gave different types of error message, none of which were any clearer.

      • VikasB's avatar
        VikasB
        Boss

        Hi dkytasaari  You are missing ending quote(") in your query.

        Here is updated one

        <#assign userLOC= rest("2.0","/search?q=" + "SELECT login from users where id='${page.context.user.id}'"?url).data.items[0] />
        <div>
            ${userLOC.login}
        </div>

        Also, I do not think so there is any location field in API.