Page 1 of 1

Navigator: is there a simple way to reverse the array?

Posted: Sun Apr 03, 2016 6:50 am
by Andrew Prior
In CMSMS 2.1.2:
Site will add 50 to 60 articles per year in several areas of the site... is it possible to set Navigator to list menu items last to first instead of the default first to last, so that the last item added is always at the top of the list?

Re: Navigator: is there a simple way to reverse the array?

Posted: Sun Apr 03, 2016 6:59 pm
by Jeff

Re: Navigator: is there a simple way to reverse the array?

Posted: Mon Apr 04, 2016 12:40 am
by calguy1000
Yes....

{$nodes=array_reverse($nodes)}
directly before the foreach loop should reverse the list of everything.

You may need to enable permissive smarty in the config.php
(it's in the config reference doc).

Re: Navigator: is there a simple way to reverse the array?

Posted: Mon Apr 04, 2016 10:31 am
by Andrew Prior
Thankyou.
As a complete amateur, I can insert the smarty code into the template, and I have enabled the permissive smarty in config.php which allows the template to load.

But I have no idea how to configure the reverse array function so that Calguy's code actually does anything.

I have in Navigator
{Navigator start_level="4" collapse="1" ... ion test"}
which works as intended, except it does not reverse the array.

Re: Navigator: is there a simple way to reverse the array?

Posted: Mon Apr 04, 2016 11:18 am
by velden

Code: Select all

...
{if !isset($depth)}{$depth=0}{/if}

{if isset($nodes)}{strip}
{$nodes=array_reverse($nodes)} 
<ul>
  {foreach $nodes as $node}
    {if $node->type == 'sectionheader'}
...

Re: Navigator: is there a simple way to reverse the array

Posted: Tue Apr 05, 2016 9:16 pm
by Andrew Prior
Thank you all. It works when I have this as the last few lines of the Navigator template

Code: Select all

{/strip}{/function}
{$nodes=array_reverse($nodes)}
{if isset($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}

Re: Navigator: is there a simple way to reverse the array?

Posted: Tue Apr 05, 2016 9:21 pm
by velden
Andrew Prior wrote:Thank you all. It works when I have this as the last few lines of the Navigator template

Code: Select all

{/strip}{/function}
{$nodes=array_reverse($nodes)}
{if isset($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}
Better change order of those two lines for obvious reason:

Code: Select all

{/strip}{/function}
{if isset($nodes)}
{$nodes=array_reverse($nodes)}
{Nav_menu data=$nodes depth=0}
{/if}

Re: Navigator: is there a simple way to reverse the array?

Posted: Tue Apr 05, 2016 9:24 pm
by Andrew Prior
Ta... How can I apply [Solved] to the original post? It doesn't seem to let me edit it?