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

 

 

    • lc-garcia's avatar
      lc-garcia
      Guide

      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

        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