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

    I was searching the forum for few hours but couldn’t find the solution for my problem..

    I need a snippet code that will check if current selected menu has active child, if it has, I need to return menu name, if doesn’t, I have to return empty string.

    Thank you!

    now the code I have is:

    <?php
    $id = isset($id)? $id: $modx->documentObject[’id’];
    $field = isset($field)? $field : "pagetitle";
    $result = $modx->getDocument($id,$field);
    return $result[$field];
    ?>

    It returns all the page titles.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 17510
        • 16 Posts
        Solved with the next code:

        <?php
        $id = isset($id)? $id: $modx->documentObject[’id’];
        $field = isset($field)? $field : "pagetitle";
        $result = $modx->getDocument($id,$field);
        $resu = $modx->getActiveChildren2($id);
        if(count($resu))
        {
        return $result[$field];
        }
        else
        {
        return ’’;
        }
        ?>


        and this code add style display none inside the div

        <?php
        $id = isset($id)? $id: $modx->documentObject[’id’];
        $field = isset($field)? $field : "pagetitle";
        $result = $modx->getDocument($id,$field);
        $resu = $modx->getActiveChildren2($id);
        if(count($resu))
        {
        return ’’;
        }
        else
        {
        return ’style="display:none;"’;
        }
        ?>
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It helps if you use the forum’s code tags to enclose code; it’s the # button.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org