Page 1 of 1
					
				Smarty Modifier to Reverse Sort Arrays
				Posted: Tue May 27, 2008 9:06 pm
				by Nullig
				Here's a Smarty plugin (modifier) to reverse sort arrays. I needed something to reverse the menu order for a client, where the template called for the menu items to be aligned right, which caused them to load from right to left. rather than reorder the pages, which would be confusing for the client, I created this plugin.
Just copy the attached file (rename it to modifier.reverse_array.php) to your lib/smarty/plugins directory. 
To reverse sort an array, like $nodelist in your menu template, just change:
Code: Select all
{foreach from=$nodelist item=node}
to:
Code: Select all
{foreach from=$nodelist|@reverse_array item=node}
This will work for single level menus.
Nullig
 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Tue May 27, 2008 9:10 pm
				by calguy1000
				or {capture assign='newlist'}{$nodelist|array_reverse}{/capture}  
should do the same thing.
			 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Wed May 28, 2008 8:26 am
				by cyberman
				Nullig wrote:
This will work for single level menus.
Many thanks - just needed  

.
 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Fri Aug 29, 2008 2:02 pm
				by lainyrache
				Hi 
I need to achieve this on cssmenu horizontal. 
Is there any quick method or is that a whole new ball game. 
Many thanks for any tips.
			 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Sun Aug 31, 2008 6:30 am
				by Dr.CSS
				If you have a menu you need to put to the right, like the aligned right talked about in the first post there are ways to do this with CSS w/o making your menu item reverse order, I do it all the time...
			 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Mon Sep 01, 2008 12:20 pm
				by lainyrache
				   float:left;
   text-align:right has worked a treat for me... 
Couldn't see the wood for trees 
Many thanks Mark
			 
			
					
				Re: Smarty Modifier to Reverse Sort Arrays
				Posted: Sun Oct 09, 2011 8:27 pm
				by nxthor
				THX for the code! got me a short solution-search for my little problem 
 
use it to reverse the order off all subpages to one page in a submenu/overview-page, since the customer wants to have the last added entry at the top.
surely, i could have filled a var at the beginning each loop, and print out afterwards, but this seems to be more readable for my successor.