We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27170
    • 3 Posts
    Hi folks, it’s my first post here so if it’s in the wrong place please feel free to flame smiley

    I’m having a problem with a snippet i’ve written which returns the parent page title or the current page title using the isfolder variable. The code is written as follows...

    <?php
    $docId = $modx->documentIdentifier;
    if ($isFolder == 0) {
    	$parent = $modx->getParent($docId, 1, 'pagetitle');	
     	return $parent['pagetitle'];
     	exit;
    }
    if ($isFolder == 1) {
     	$parent = $modx->getPageInfo($docId, 1, 'pagetitle');
     	return $parent['pagetitle'];
            exit;
    }
    ?>


    I’m calling the snippet as follows...

    [[parentTitle?&isFolder=`[*isfolder*]`]]


    The above works fine in a page template but falls over when used in a chunk, returning the pagetitle if the page is a page and returning nothing if the page is a folder huh

    Can anyone tell me what i’m doing wrong? I’d like to be able to use the code in the chunk as it’s used on every page except my homepage and if i feel like redesigning my site it would make it much easier to update just the chunk instead of a few templates.

    Cheers

    [Edit]
    Sorry, forgot to mention my setup!

    Modx Version: 0.9.6
    Server: Apache 2.0.54
    PHP Version: 5.23.
    Not sure of the mysql version, sorry.
      • 21496
      • 225 Posts
      Hi - It doesn’t look like you’re doing something wrong. Did you clear the site cache? Sometimes this helps.
        René
        • 7231
        • 4,205 Posts
        And also you may want to call the snippet uncached [! !] rather than [[ ]]

        [!parentTitle?&isFolder=`[*isfolder*]`!]
          [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]
          • 27708 MODX Staff
          • 2,502 Posts
          I have read that sometimes there can be problems when there is no space in the call between the ? and the first &. I haven’t experienced it but it may be a factor. But as dev_cw said making it uncacheable often helps. (One day I’ll figure out the whole cache relationship thing in MODx with snippet calls).

          ATB,

          Jay
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 27170
            • 3 Posts
            Thanks everyone. The caching was the problem, using your method dev_cw fixed it.

            Cheers.
              • 7231
              • 4,205 Posts
              Good to hear you got it working. Nice simple snippet, just a few lines of code and you are able to get the results you want. MODx rocks.
                [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]
                • 7455
                • 2,204 Posts
                Nice work but could be smaler especialy if the isfolder option is always used.

                <?php
                $docId = $modx->documentIdentifier;
                $isFolder = $modx->documentObject['isfolder'];
                
                if ($isFolder == 0) {
                	$parent = $modx->getParent($docId, 1, 'pagetitle');	
                 	return $parent['pagetitle'];
                }else{
                    return 	$modx->documentObject['pagetitle'];
                }
                ?>
                


                now no parameter is needed just place the snippet
                greets Dimmy
                  follow me on twitter: @dimmy01