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

    Can anyone tel me why the following code works fine in 2.07 but not in 2.1.1?

    <img src="[[+filename:notempty=`uploads/thumbs/[[+id]]/[[+filename]]`:default=`uploads/images/noimage.gif`]]" alt="[[+code]]" />
      • 3749
      • 24,544 Posts
      What is setting the [[+filename]] placeholder and the [[+id]] placeholder and [[+code]] placeholders?
        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
        • 14107
        • 21 Posts
        This snippet

        <?php
        $path = MODX_CORE_PATH . 'components/items/';
        $modx->setOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS, true);
        $modx->addPackage('items',$path . 'model/','brox_');
        
        $c = $modx->newQuery('Item');
        $c->leftJoin('Images','Images');
        
        $c->select(array (
            'Item.*',
            'Images.filename'
        ));
        
        $c->where(array(category_id => $_GET['category_id']));
        $c->sortby('code','DESC');
        
        $items = $modx->getCollection('Item', $c);
        
        
        foreach($items as $item) {
        
           $itemArray = $item->toArray();
           $output .= $modx->getChunk($tpl,$itemArray);
        
        
        }
        
        return $output;
          • 3749
          • 24,544 Posts
          category_id may not be in the $_GET array any more.

          Can you retrieve it with xPDO (or hard-code 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
            • 14107
            • 21 Posts
            Hi, thanks for your reply.

            Everything works fine, except I no longer see a default image if I haven’t added an image to an item. I just see the alt tag.

            This is since I updated to 2.1.1.

            I have another identical site running 2.0.7 and it shows the default image if there are no images added an item.

            In both sites I can see the image if I have added one.
              • 3749
              • 24,544 Posts
              I’m not sure what to suggest, there haven’t been any changes to the output modifiers since March (not sure when 2.0.7 came out). I believe this would work.


              <img src="[[+filename:notempty=`uploads/thumbs/[[+id]]/[[+filename]]`]] [[+filename:empty=`uploads/images/noimage.gif`]]" alt="[[+code]]" />


              I would probably do it with a snippet, however. Something like this:

              <img src = "[[!SetImage? &fname=`[[!filename]]` &fid=`[[+id]] ]]" alt="[[+code]]" />


              <?php
              /* SetImage snippet */
              
              return empty($fname) ? 'uploads/images/noimage.gif' : 'uploads/thumbs/' . $fid . '/' . $fname;

                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
                • 14107
                • 21 Posts
                Hi BobRay

                Thank you for your help. I couldn’t get either of your suggestions to work exactly but with a bit of experimentation, I got the following to work...

                <img src="[[+filename:notempty=`uploads/thumbs/[[+id]]/`]][[+filename:empty=`uploads/images/noimage.gif`]]" alt="[[+code]]" />


                Not sure why though!