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

    I've developed some related pages functionality by following the tutorial: http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/creating-a-multi-select-box-for-related-pages-in-your-template provided on the MODX website. I'm running MODX 2.3.1. If I clear the cache and reload the page where the snippet is called, I receive the following error message in the error log, although the chunk still outputs as I'd expect (with the url to the target page):

    (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()

    I've checked my code against what has been provided in the tutorial and cannot see any differences (other than my additional line of code on line 12 of the snippet) and I've included my code below. I've tried enabling debug mode in system settings and don't seem to get too much more relevant information. I've also tried removing my code and replacing it by copying and pasting the relevant code samples from the tutorial into the chunk and snippet and I still get the error message.

    I'd be extremely grateful for any help anyone can provide.

    Chunk
    <li>
    		<a href="[[~[[+id]]]]" title="[[+longtitle]]">[[!Gallery? &album=`[[+gallery-images]]`&tag=`featured`&limit=`1`&thumbWidth=`250`&thumbHeight=`90`&thumbZoomCrop=`1`&thumbTpl=`ImageTpl`]]</a>
    		   <p><a href="[[~[[+id]]]]" title="[[+longtitle]]">[[+longtitle]]</a></p>
    </li>
    


    Snippet
    if (empty($input)) { return 'This cruiser is so unique, that we don\'t have anything similar to it!'; }
    $tpl = $modx->getOption('tpl',$scriptProperties,'RelatedCruisersTpl');
    if ($modx->getChunk($tpl) == '') { return 'We found some similar cruisers, but cannot show them at the moment.'; }
    $ids = explode(',', $input);
    $output = array();
    foreach ($ids as $key => $value) {
      $resource = $modx->getObject('modResource',array(
        'published' => 1,
        'id' => $value));
      if ($resource instanceof modResource) {
        $fields = $resource->toArray();
        $fields['gallery-images'] = $resource->getTVValue('GalleryImages');
        $output[] = $modx->getChunk($tpl,$fields);	
      }
    }
    return implode('',$output);
    


    Phillip

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      I can't think of any reason that wouldn't work unless the nested link tag is confusing getChunk().

      A possible workaround would be to replace the link tag:

      [[~[[+id]]]]


      with this:

      [[+link]]


      and add this to your code in the loop:

      $fields['link'] = $modx->makeUrl($value, "", "", "full");


        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
        • 48421
        • 19 Posts
        Hi BobRay

        Thanks for the work around, that seems to have worked perfectly.

        Phillip
          • 3749
          • 24,544 Posts
          I'm glad it worked for you. One word of warning: It won't work with resources you've just created in code unless you call $modx->reloadContext('contextTheResourceIsIn') before calling makeUrl().
            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
            • 4172
            • 5,888 Posts
            you could also try:

            [[[[+id:isnot=``:then=`~[[+id]]`:else=``]]]]


              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 26401
              • 247 Posts
              really?

              [[[[+id:isnot=``:then=`~[[+id]]`:else=``]]]]
              instead of
              [[~[[+id]]]]
              ?

              while I'm glad this works, it seems strange that it would be necessary.
                • 3749
                • 24,544 Posts
                I think the issue may be that you're not validating the $input used in line 4 or the $value used in line 9. If the input is malformed or empty, $value may be empty and that will freak out makeUrl().
                  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