We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    ADDED TO REPOSITORY

    This is a snippet to output a certain string or chunk when it meets certain criteria, such as the current document id is listed on $id parameter, or the current document parent id is listed on $parent parameter. It can react to $notid or $notparent parameter as well, which is the opposite from the previous example.

    I use this a lot when I use @INHERIT binding on some of my TV. With this snippet, I can determined on which document level the output has to be parsed and so on. Hope you guys might find it useful.

    Sincerely,
    Wendy Novianto
    DJAMOER


    <?php
    /**
     * CurrDocOut
     * Outputing a desired output from string being passed from parameters or
     * from chunk name depending on the ID to be included or excluded. It will
     * output nothing if all the condition was not matched.
     *
     * Parameters:
     * - $id - Documents ID separated with comma to be included
     * - $notid - Documents ID separated with comma to be excluded
     * - $parent - Parent ID separated with comma to be included
     * - $notparent - Parent ID separated with comma to be excluded
     * - $out - String to be outputed, don't use it together with $outChunk parameter
     * - $outChunk - Chunk name to be outputed, don't use it together with $out parameter
     */
    print_r($modx->documentListing);
    // Parse $id parameter
    if(isset($id)) {
    	$tempid = split(',', $id);
    	$id = array();
    	foreach($tempid as $v) {
    		if(is_numeric($v)) $id[] = (int) $v;
    	}
    }
    else $id = array();
    // Parse $notid parameter
    if(isset($notid)) {
    	$tempid = split(',', $notid);
    	$notid = array();
    	foreach($tempid as $v) {
    		if(is_numeric($v)) $notid[] = (int) $v;
    	}
    }
    else $notid = array();
    // Parse $parent parameter
    if(isset($parent)) {
    	$tempid = split(',', $parent);
    	$parent = array();
    	foreach($tempid as $v) {
    		if(is_numeric($v)) $parent[] = (int) $v;
    	}
    }
    else $parent = array();
    // Parse $notparent parameter
    if(isset($notparent)) {
    	$tempid = split(',', $notparent);
    	$notparent = array();
    	foreach($tempid as $v) {
    		if(is_numeric($v)) $notparent[] = (int) $v;
    	}
    }
    else $notparent = array();
    
    // Count $id & $notid array
    $idsum = count($id);
    $notidsum = count($notid);
    $parentsum = count($parent);
    $notparentsum = count($notparent);
    
    // Outputing the right content
    $output = '';
    $condition = true;
    if($idsum > 0) $condition = $condition && in_array($modx->documentIdentifier, $id);
    if($notidsum > 0) $condition = $condition && !in_array($modx->documentIdentifier, $notid);
    if($parentsum > 0) $condition = $condition && in_array($modx->documentObject['parent'], $parent);
    if($notparentsum > 0) $condition = $condition && !in_array($modx->documentObject['parent'], $notparent);
    if($condition) {
    	if(isset($out) && trim($out) != '') $output .= $out;
    	if(isset($outChunk) && trim($outChunk) != '') $output .= $modx->getChunk($outChunk);
    }
    
    // Return output string
    return $output;
    ?>
    
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 6726
      • 7,075 Posts
      Waow Wendy, this is a great snippet I see a lot of potential use for it ! (glad to see you’re back, hope you’ve found a decent internet connection, btw)

      Thanks for this one smiley
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l&#39;outil id
        • 32241
        • 1,495 Posts
        Quote from: davidm at Jun 26, 2006, 07:41 AM

        Waow Wendy, this is a great snippet I see a lot of potential use for it ! (glad to see you’re back, hope you’ve found a decent internet connection, btw)

        Thanks for this one smiley


        I’m still looking for a decent internet connection here. lol
        I’ll just keep an eye on the current development progress and keep posting some codes that might prove to be useful for the community.

        Best regards,
        Wendy Novianto
        AKA: DJAMOER
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media