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

    I have the following Chunk:

    `displayRelatedChildList`

    [[getResources?
        &resources=`[[*relatedProducts]]`
        &tpl=`displayChildList.tpl`
        &limit=`3`
        &includeTVs=`1`
        &processTVs=`1`
        &includeContent=`0`
        &depth=`0`
        &sortby=`FIELD(modResource.id,[[*relatedProducts]])`
        &sortdir=`ASC`
        &showHidden=`0`
        &showUnpublished=`0`
        &idx=`[[+idx]]`
    ]]


    and the template that it uses:

    `displayChildList.tpl`

    <div id="productUL" class="span3 textCenter">
        <a href="[[~[[+id]]]]"><img id="image" alt="[[!if? subject=`[[+longtitle]]` &operator=`isempty` &then=`[[+pagetitle]]` &else=`[[+pagetitle]] [[+longtitle]]`]]" src="[[+tv.thumbs]]"/></a>
        <h3><a href="[[~[[+id]]]]">[[+menutitle:empty=`[[+pagetitle]]`]]</a></h3>
    </div>


    and the call from the page:

    [[$displayRelatedChildList]]


    Everything is working as expected until I tried un-publishing a page. The problem I am facing at the moment is that even though the page is unpublished AND the page is set to `Hide from menus` the resource is still being displayed.

    Any advise would be greatly appreciated.

    Here is some of the data returned by the call without the template. The resource ID `963` is set to un-published and hidden from menus yet still being displayed:

    Array
    (
        [tpl] => displayChildList.tpl-
        [tplOdd] => 
        [tplFirst] => 
        [tplLast] => 
        [tplWrapper] => 
        [wrapIfEmpty] => 
        [sortby] => FIELD(modResource.id,945,963,40)
        [sortbyTV] => 
        [sortbyTVType] => string
        [sortbyAlias] => 
        [sortbyEscaped] => 0
        [sortdir] => ASC
        [sortdirTV] => DESC
        [limit] => 3
        [offset] => 0
        [tvFilters] => 
        [tvFiltersAndDelimiter] => ,
        [tvFiltersOrDelimiter] => ||
        [depth] => 0
        [parents] => 
        [includeContent] => 0
        [includeTVs] => 1
        [includeTVList] => 
        [showHidden] => 0
        [showUnpublished] => 0
        [showDeleted] => 
        [resources] => 945,963,40
        [processTVs] => 1
        [processTVList] => 
        [prepareTVs] => 1
        [prepareTVList] => 
        [tvPrefix] => tv.
        [idx] => 0
        [first] => 1
        [last] => 2
        [toPlaceholder] => 
        [toSeparatePlaceholders] => 
        [debug] => 
        [where] => 
        [dbCacheFlag] => 0
        [context] => 
        [tplCondition] => 
        [tplOperator] => ==
        [conditionalTpls] => 
        [odd] => 0
        [id] => 945
        [type] => document
        [contentType] => text/html
        [pagetitle] => 
        [longtitle] => 
        [description] => 
        [alias] => 
        [link_attributes] => 
        [published] => 1
        [pub_date] => 0
        [unpub_date] => 0
        [parent] => 842
        [isfolder] => 
        [introtext] => 
        [richtext] => 1
        [template] => 4
        [menuindex] => 7
        [searchable] => 1
        [cacheable] => 1
        [createdby] => 1
        [createdon] => 2013-05-21 01:20:16
        [editedby] => 2
        [editedon] => 2013-06-04 09:35:30
        [deleted] => 
        [deletedon] => 0
        [deletedby] => 0
        [publishedon] => 2012-04-05 18:04:00
        [publishedby] => 1
        [menutitle] => 
        [donthit] => 
        [privateweb] => 
        [privatemgr] => 
        [content_dispo] => 0
        [hidemenu] => 1
        [class_key] => modDocument
        [context_key] => web
        [content_type] => 1
        [uri] => 
        [uri_override] => 0
        [hide_children_in_tree] => 0
        [show_in_tree] => 1
        [properties] => 
        [tv.thumbs] => 
        [tv.relatedProducts] => 40,41,42
        [tv.sldr1img1] => 
        [tv.sldr1img1txt] => 
        [tv.productData] =>
    )
      • 31354
      • 24 Posts
      Sorry, my current version is 2.2.1 so this should be moved to v2.2 I guess. Not sure how to do that.
        • 3749
        • 24,544 Posts
        If that resource is in the &resources property (and it looks like it is), it will be shown no matter what its settings are because you're saying explicitly that you want it.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 31354
          • 24 Posts
          OK, that does make sense. The reference is in the &resources because it is a CSV TV dictating the resources to use on a/that particular page. However, since there are ~150 main pages that can be used I didn't account for un-publishing or hiding from the menu.

          For future reference, would there have been a better way to accomplish this so that we don't have to go back and remove the reference from each individual page whenever we un-publish or hide from menu a referenced resource?

          Thanks for the answer BobRay!

          BTW: I got your book; I haven't got through it yet but a great resource none the less.
            • 3749
            • 24,544 Posts
            Thanks for buying my book. smiley

            I can't think of anything to suggest other than creating a custom snippet instead of getResources. Your custom snippet could check the hidemenu and published fields.

            The snippet would not be simple, but I think it would be *way* faster than getResources and the multiple output modifiers.

            If I'm understanding what you want, the snippet would look something like this (untested):

            Tpl chunk:
            <div id="productUL" class="span3 textCenter">
                <a href="[[+url]]"><img id="image" alt="[[+alt]]" src="[[+src]]"/></a>
                <h3><a href="[[+url]]">[[+menu]]</a></h3>
            </div>


            Tag:
            [[DisplayRelatedChildren? &tpl=`displayChildList.tpl`]]


            Snippet Code
            <?php
            /* DisplayRelatedChildren snippet */
            $output = '';
            /** @var $modx modX */
            /** @var $scriptProperties array */
            $tplName = $modx->getOption('tpl', $scriptProperties, '');
            
            if (empty($tplName)) {
               return 'Tpl Chunk not found';
            }
            
            $related = $modx->resource->getTVValue('relatedProducts');
            if (empty($related)) {
                $related = array();
            }
            
            $mainIds = explode(',', $related);
            if (empty($mainIds) ) {
                return 'No Resources Found'; // probably want to change this
            }
            
            natsort($mainIds);
            
            foreach ($mainIds as $mainId) {
                $doc = $modx->getObject('modResource', $mainId);
                $c = $modx->newQuery('modResource');
                $c->where(array(
                   'published => true',
                   'hidemenu' => false
                  ));
                $c->limit(3);
                $c->sortby('id:DESC');
            
                $children = $doc->getMany('Children', $c);
            
                foreach ($children as $child) {
                    /** @var  $child modResource */
                    $idx = $child->get('id');
                    $url = $modx->makeUrl('idx', "", "", "full");
                    $pagetitle = $child->get('pagetitle');
                    $longtitle = $child->get('longtitle');
                    $menutitle = $child->get('menutitle');
                    $src = $child->getTVValue('tv.thumbs');
            
                    $alt = empty($longtitle) ? $pagetitle : $pagetitle . ' ' . $longtitle;
                    $menu = empty($menutitle)? $pagetitle : $menutitle;
            
                    $fields = array(
                        'url' => $url,
                        'src' => $src,
                        'alt' => $alt,
                        'menu' => $menu,
                    );
            
                    $output .= $modx->getChunk($tplName, $fields);
                }
            }
            
            return $output;
            
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 31354
              • 24 Posts
              Thanks BobRay!, I'll play around with this and see if I can get it to work.
                • 3749
                • 24,544 Posts
                Quote from: VDISP at Jun 10, 2013, 11:58 PM
                Thanks BobRay!, I'll play around with this and see if I can get it to work.

                Don't thank me until it works. wink
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting