We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26958
    • 9 Posts
    We have a snippet called on our template where we want to show some sub navigation guides on selected pages. We’re trying to do something like this:

    if ($modx->documentListing[$alias] == 'page1') {
    	echo '<div id="subnav"><ul><li>Link 1</li><li>Link 2</li></ul></div>
    }
    


    ... but that doesn’t work. How can we call the for a given page in the Snippet like this?


    Thanks,
    Shaun
      • 7231
      • 4,205 Posts
      Why use the alias. I would recommend using the document ID which will always be unique. But if you want to use the alias it is better to use the documentObject rather than the documentListing function:

      if ($modx->documentObject['alias'] == 'page1') {
      	return '<div id="subnav"><ul><li>Link 1</li><li>Link 2</li></ul></div>
      }


      Or use the id:
      if ($modx->documentIdentifier == 2) {
      	return '<div id="subnav"><ul><li>Link 1</li><li>Link 2</li></ul></div>
      }


      Notice I used return rather than echo, in this case it will not make much difference but it is a good practice to use return in snippets since it will work with every case.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 26958
        • 9 Posts
        That’s exactly what we were after. Thanks!