Fórumok

Structure/Template sorting in velocity?

thumbnail
Ritesh Gajera, módosítva 11 év-val korábban

Structure/Template sorting in velocity?

Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
Hi All,
I would tried to implement sorting in velocity with help of three exp which I defined as below:

1 )
#foreach ($obj in $sortTool.sort($objects, "fieldnametosorton")
Display data from the sorted list here like $obj.fieldname
#end

2) since we were sorting on a child field we had to first build an array of maps and then sort on that since the sort method can't seem to access the child field:
#set ($array = [])
#foreach ($obj in $objects)
#set ($void = $array.add( { "field1" : $obj.getData(), "childfield" : $obj.childfield.getData() } ) )
#end

#foreach ($obj in $sortTool.sort($array, "childfield")
<p>This is a line sorted on $obj.childfield</p>
#end
3)
OtherWay

#set ($menuItems= [])
#set ($tmp = $menuItems.add({"title" : "item1", "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item3", "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item2", "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item4", "url" : "http://www.google.com"}))

#foreach ($item in $sortTool.sort($menuItems, 'title:asc'))
<a href="$item.url">$item.title</a><br>
#end

#foreach ($item in $sortTool.sort($menuItems, 'title:desc'))
<a href="$item.url">$item.title</a><br>
#end

but I'm not able get an proper idea how to implement sorting in velocity from these above example. so
Plz provide any suggestion or share any thought here,

Thanks & Regards,
Ritesh Gajera
thumbnail
Amos Fong, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
Hi Ritesh,

What is your issue? It seems to work for me.
Hiral Ramavat, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Regular Member Bejegyzések: 103 Csatlakozás dátuma: 2012.02.13. Legújabb bejegyzések
Are you trying to do sorting with above three ways as you mentioned? Because it seems fine with code.

Thanks,
Hiral
thumbnail
Ritesh Gajera, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
Hi,

I tried two of them but its not working fine based on my specific requirement to related the issue.

Issue is:

I have a requiement to have a field(sibling) named "order" in structure which is of string type.The whole structure(item) should be displayed in sorted order based on this "order" field.There is an inbuilt method "sorter.sort" in velocity but I am not able to understand its usage.

Has any one sorted the content using specific sibling field in template.vm?

Please provide me any pointers or guidance related to this issue.

Thanks & Regards,
Ritesh Gajera
thumbnail
Ritesh Gajera, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
Hiral Ramavat:
Are you trying to do sorting with above three ways as you mentioned? Because it seems fine with code.

Thanks,
Hiral



Hi Hiral,

Above of three codes works fine but with the help of these three code when I'm implementing my spotlight portlet then its not work. Because the content of spotlight is not rearrange it for the same code. Like as I also tried to used bubble sort in velocity but I'm not able to do that.
If You know how to rearrages / reorders the content in template file then please suggest me.

Thanks & Regards,
Ritesh Gajera
thumbnail
Ritesh Gajera, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
Hi Amos,

I have a requiement to have a field(sibling) named "order" in structure which is of string type.The whole structure(item) should be displayed in sorted order based on this "order" field.There is an inbuilt method "sorter.sort" in velocity but I am not able to understand its usage.

Has any one sorted the content using specific sibling field in template.vm?

Please provide me any pointers or guidance related to this issue.

Thanks & Regards,
Ritesh Gajera
thumbnail
Amos Fong, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
Can you post your exact code that you are trying to run?

It also would help if you print out all the sibling objects directly to the screen so you can see their exact field values.
thumbnail
Ritesh Gajera, módosítva 11 év-val korábban

RE: Structure/Template sorting in velocity?

Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
Hi Amos,
Finally, I have found the little bit way without used the sorting in my template file and i achieved the things which i needed to implement in its.

Here, Template code as below:

<!DOCTYPE html>

#parse ($init)

<html class="#language("lang.dir")" dir="#language("lang.dir")" lang="$w3c_language_id">

<head>

</head>

<body>
<div class="spotlight" >
<h2>Spotlight</h2>
<ul id="newsslider">
#set($item1 = 0)
#foreach($item in $Content.getSiblings())
#set($item1 = $item1+1)
#if($item1<=8)
#if($item.Display.getData()!="")

<li>
<a><img src="$item.Image.getData()" width="113" height="35" alt="no Image available"/></a>
<h3><a href="$item.Link.getData()">$item.Title.getData()</a></h3>
#if($item.Description.getData()!="")
$item.Description.getData()
#else
<p>&nbsp;</p>
#end
</li>
#end
#end
#end
</ul>
</div>
</body>

</html>

But, Is there any other ways to rearranges the spotlight content through sorting methods in template file?

Any pointer will be helpful.

Thanks & Regards,
Ritesh Gajera