We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51318
    • 9 Posts
    Hi all,

    I use WayFinder to manage the menu.
    I would like to know how to do to display some items in the menu (or enable some items) only when my variable $_session["connected"] is defined.

    thanks
    Franck
      • 51318
      • 9 Posts
      Solved !
      1) In a shunk, I've added this: [[menu]]
      2) the snippet of menu is:
      <?php
      // Si l'utilisateur est enregistré, tous les menus sont affichés
       if (isset($_SESSION['connected'])) {
      	
          $output = $modx->runSnippet('Wayfinder',array(
      		'startId' => '1',
      		'outerTpl'=> 'menuOuter',
      		'rowTpl'  => 'menuRow',
      		'innerTpl'=> 'menuInner',
      		'innerRowTpl' => 'menunnerRow',
      		'hereClass' => 'current_page_item',
      		'firstClass' => '',
      		'lastClass' => '',
          	'excludeDocs' => ''
      	));
       } else
      // sinon, masquer certaines pages
       {
          $output = $modx->runSnippet('Wayfinder',array(
      		'startId' => '1',
      		'outerTpl'=> 'menuOuter',
      		'rowTpl'  => 'menuRow',
      		'innerTpl'=> 'menuInner',
      		'innerRowTpl' => 'menunnerRow',
      		'hereClass' => 'current_page_item',
      		'firstClass' => '',
      		'lastClass' => '',
          	'excludeDocs' => '2,4,6,29'
      	));
       }
      	
      echo $output;
      
      
        • 4041
        • 788 Posts
        Glad you got the issue sorted, here is a shorter version that should work ( does the same thing with a little less code is the only difference).
        Another thing with snippets its better to add all the output into a variable, then return instead of echo. Just fyi smiley

        <?php
        $exclude_docs = isset($_SESSION['connected']) ? '2,4,6,29' : ''; 
            
        $output = $modx->runSnippet('Wayfinder',array(
                'startId'     => '1',
                'outerTpl'    => 'menuOuter',
                'rowTpl'      => 'menuRow',
                'innerTpl'    => 'menuInner',
                'innerRowTpl' => 'menunnerRow',
                'hereClass'   => 'current_page_item',
                'firstClass'  => '',
                'lastClass'   => '',
                'excludeDocs' => $exclude_docs
            ));
        
        return $output;
        ?>
          xforum
          http://frsbuilders.net (under construction) forum for evolution