Forum Discussion

lc-garcia's avatar
13 years ago

Sorting blogs by alphabetical order

Hi there,

 

    I'm using a REST API call like this

 

    /restapi/vc/boards/style/blog/nested/

 

    in order to iterate through a list and populate a component with links  for such blogs. Is there anyway I can get this list sorted out in alphabetical order? The XML response include something like

 

<board type="board" href="/blogs/id/blog-1">

<id type="string">net-blog-test</id>

<owner type="user" null="true"/>

<blog type="boolean">true</blog>

<interaction_style type="string">blog</interaction_style>

<user_created type="boolean">false</user_created>

<description type="string">Sample blurb</description>

<title type="string">Test Blog </title>

<short_title type="string">Net Blog</short_title>

</board>

<board type="board" href="/blogs/id/blog-2">

<id type="string">apps-blog</id>

<owner type="user" null="true"/>

<blog type="boolean">true</blog>

<interaction_style type="string">blog</interaction_style>

<user_created type="boolean">false</user_created>

<description type="string"/>

<title type="string">Another Blog</title>

<short_title type="string">Apps Blog</short_title>

</board>

 

     and I'd like to have sorted by bold title value. Is it possible to do this adding parameters to the call, or is it something that can be done with the FreeMarker #list?

 

Thanks,

Luis

 

 

7 Replies

  • lc-garcia's avatar
    lc-garcia
    Guide
    13 years ago

    Hi Adam,

     

         The built in is working just fine. I'm now facing a REST API call issue.

     

         I'm trying to retrieve certain Community's blog list with

     

              <#assign global_blogsCount = rest('boards/style/blog/nested/count').value/>  

     

         However, when I try to use this value for a very simple calculation such as

     

              <#assign leftColumnEnd = (global_blogsCount/2) />

     

         I get the following error.

     

              Expression global_blogsCount is not numerical

     

         Could you please advice?

     

    Gracias,

    Luis

         

         

  • AdamN's avatar
    AdamN
    Khoros Oracle
    13 years ago

    As far as freemarker is concerned, the value you're getting back is a string. So if you want to use it as a number, you need to convert it. There's a "number" built-in that can be used with strings. For example:

     

    <#assign global_blogsCount = rest('boards/style/blog/nested/count').value?number />  

     In case you're curious, you can find a full listing of the available freemarker built-ins here:

    http://freemarker.sourceforge.net/docs/ref_builtins.html

     

    I hope this helps!

     

    -Adam

  • lc-garcia's avatar
    lc-garcia
    Guide
    13 years ago

    Thanks Adam,

     

         That worked out the issue. Could you please point out what's wrong on this snippet?

     

         <#if (global_blogsCount % 2) == 1)>

              <#assign leftColumnEnd = (leftColumnEnd?int) + 1 />
         <#/if>
         <#list global_blogs.board?sort_by("title") as blog>
              <#if gblogIdx != 0>
                   <#if (gblogIdx == (leftColumnEnd + 1) >
                        <#assign blogMenuContentAlpha = blogMenuContentAlpha + '</div><div class="hp-sub-nav-row blog-list-right">' />
                   <#/if>

              </#if>
               <#assign blogMenuContentAlpha = blogMenuContentAlpha + '<div class="hp-nav-col"><ul><li><a href="${blog.@view_href}">${blog.title}</a></li></ul></div>' /> <#assign gblogIdx = gblogIdx + 1 />
         </#list>

     

          Lines in bold are breaking my code

     

    Gracias,

    Luis

  • AdamN's avatar
    AdamN
    Khoros Oracle
    13 years ago

    It looks like the second bolded line of code has an unmatched parenthesis, so that could be one issue. Does fixing that resolve everything? If not, could you reply back with the details of the error message you're receiving?

  • lc-garcia's avatar
    lc-garcia
    Guide
    13 years ago

    Thanks Adam

     

         In addition to that, there were another syntax errors. Will keep debugging

     

    Gracias,

    Luis