Smarty Modifier to Reverse Sort Arrays

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Smarty Modifier to Reverse Sort Arrays

Post 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
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Smarty Modifier to Reverse Sort Arrays

Post by calguy1000 »

or {capture assign='newlist'}{$nodelist|array_reverse}{/capture} 
should do the same thing.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cyberman

Re: Smarty Modifier to Reverse Sort Arrays

Post by cyberman »

Nullig wrote: This will work for single level menus.
Many thanks - just needed  :).
lainyrache
Forum Members
Forum Members
Posts: 106
Joined: Thu Oct 05, 2006 11:27 am

Re: Smarty Modifier to Reverse Sort Arrays

Post 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.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Smarty Modifier to Reverse Sort Arrays

Post 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...
lainyrache
Forum Members
Forum Members
Posts: 106
Joined: Thu Oct 05, 2006 11:27 am

Re: Smarty Modifier to Reverse Sort Arrays

Post by lainyrache »

  float:left;
  text-align:right has worked a treat for me...
Couldn't see the wood for trees
Many thanks Mark
nxthor

Re: Smarty Modifier to Reverse Sort Arrays

Post 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.
Post Reply

Return to “Tips and Tricks”