Share » Forums » Developer » Preserve the order of nodes in fetch...

Preserve the order of nodes in fetch function

Preserve the order of nodes in fetch function

Friday 21 January 2011 9:04:22 am - 2 replies

Author Message

Franck Magnan

Sunday 23 January 2011 7:36:48 am

Hello Simone,
it seems you made a mistakes in your template code:

  • The content/node fetch function retrieve a node and you use it to retrieve an array.
    In your code, $menu_item is not an array but a node.
  • The content/node fetch function needs a node_id in argument and you passed it $menu which is an array

If you want to get an array of nodes, you need to use such a code :

{def
     $menu = ezini('PLPMenu', 'MenuArray', 'plp.ini')
     $nodes = array()
     $current_node = false()
}
   {foreach $menu as $node_id}
     {set $current_node=fetch( 'content', 'node', hash( 'node_id', $node_id ))}
     {if is_object($current_node)}
       {set $nodes = $nodes|append($current_node)}
     {/if}
   {/foreach}
{undef $menu $nodes}

Then, in your config file, you can get an order if you use an index.
For example, you can modify your code to get:

[PLPMenu]
MenuArray[]
MenuArray[1]=121
MenuArray[2]=60
MenuArray[3]=61
MenuArray[4]=62
MenuArray[5]=63
MenuArray[6]=111

--
Developer at Open Wide

Simone D'Amico

Monday 24 January 2011 1:15:32 am

Hi Frank,

your post helped me a lot in finding the right solution!

Instead of calling content/fetch node function outside foreach loop, now i use the foreach with $menu values and, inside I use the fetch function with single node.

In this way I preserve the right order. :)

Thanks a lot! :)

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu