We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2734
    • 165 Posts
    Umm. Can you describe what you did exactly?
    Maybe you should try if the snippet works with some static content by:
    a) create a chunk with some text in it (several lines) and name it "ListTest"
    b) create a new Document or edit an existing Document and paste the following into the content box: [[TextToList?chunk=`ListTest`]]
    c) Open the altered Document in your Browser and check if there is a generated List from your Text.
      • 4749
      • 623 Posts
      OK, I did as you said and I’m not getting anything. Just blank. Here’s what I did.

      1. I created a new doc.
      2. I created a new chunk with text for a list.
      3. Put said chunk in document. {{test}}
      4. Called the ListBuilder: [[listBuilder? chunk=`test`]]
      5. Blank page appears.

      I hope that helps...?!?!

      Thanks.
        The MODx has you...
        Utah Web Design
        • 2734
        • 165 Posts
        Now thats really weird...
        If you just put {{test}} in your Document (make sure it has no formatting tags that break this.. best is you enter it in the html view of tinyMCE), then the contents of the chunk should appear on this page if you open it in your browser. You have to put some contents into your chunk of course, but i assume this is the case. If that does not work, maybe your modx installation is flawed? Or maybe its a problem with 0.9.5? I only know 0.9.6.
        This should work anyway and has nothing to do with the snippet.. it is how chunks are supposed to work.

        If the "normal" chunk output works, try to send it to the TextToList Snippet.
        I noted, that you named the Snipped "listBuilder".. careful: as far as i know, you should remove the space in between the ? and the variable name: [[listBuilder?chunk=`test`]] or if you prefer the space, add an ampersand before your variable name [[listBuilder? &chunk=`test`]]

        Regards -- roman
          • 7231
          • 4,205 Posts
          Also try it uncached [! !].

          I just tried it on my local copy and it worked fine.

          1)create snippet

          2)create list chunk (or use TV)
          item1
          item2
          item3

          3)add call on page:
          [!listBuilder? &chunk=`ChunkName`!]

          Pretty cool.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 4749
            • 623 Posts
            Does it matter that I’m pulling it through Ditto? The call has to be cached also because it’s being called in a chunk with Ditto. I’ve got a MaxiGallery call in the same chunk...? Hmm. It should work if it’s working for both of you. It’ll probably end up being something stupid that I did. I’ve done everything, I think, exactly how it was explained. I do have a cursory understanding of ModX and how snippets work. Hmm. Thanks for the help I guess I’ll keep trying, but for what it’s worth here’s my configuration:

            ModX 0.9.6.1
            LAMP
            PHP 5

            Here’s my Ditto Call:
            [!Ditto?&documents=`6`&tpl=`tabsContentTpl`&display=`all`!]
            


            Here’s my chunk:
            <h3>[+service+]</h3>
                <table class="tab_info">
                    <tr>
            	    <td class="description"><p>[+serviceDesc+]</p>
                         [[ListBuilder? &tv=`listItems`]]
            	    </td>
                        <td class="pics">
                        [[MaxiGallery? &manage_target=`[+id+]` &view_gallery=`[+id+]` &display=`embedded` &embedtype=`slimbox` &galleryOuterTpl=`containerTpl` &galleryPictureTpl=`picTpl`&max_pic_number=`4` &max_thumb_size=`150`]]
            


            I just pasted the snippet in (I tried it with and without Sottwell’s suggestion to chane ’echo’ to ’return’) and that’s it.

            Thanks again.
              The MODx has you...
              Utah Web Design
              • 2734
              • 165 Posts
              Hi.
              Yes, calling this inside the ditto chunk is a problem. First of all, i suggest you test it outside of ditto. If that works, then you can debug your ditto call.
              As far as i know, template variables are not accessible inside ditto, unless you explicitly add them to the ditto call using the hiddenFields Parameter. Example:
              [!Ditto?&documents=`6`&tpl=`tabsContentTpl`&display=`all` &hiddenFields=`listItems`!]
              

              That way, the listItems TV should be accessible inside Ditto. I don’t know if it’s passed correctly over to the snippet though, but its worth a try.
                • 4749
                • 623 Posts
                OK. I got it working on a totally separate, blank page, outside of the ditto call. So, obviously there are some parsing issue to work out with ditto. OH, btw, I tried with the hidden field parameter, but no luck. However, the ditto call is calling a chunk where the list snippet is called. Also, the Ditto call itself is inside a chunk! tongue

                The thing that get’s me is that MaxiGallery, which is pretty complex snippet, still works - it’s in the same chunk as the list snippet. Go figure! I don’t get it, but you’re much smarter than I. SO....

                Anything else you’d like to have me try, I’m happy to.

                Thanks again.
                  The MODx has you...
                  Utah Web Design
                  • 2734
                  • 165 Posts
                  Hm after thinking about my code, i realized that the $modx->documentObject[’id’] call, might cause a problem. I think this won’t return the desired results when called inside ditto... simply because it will (probably) use the id of the Document that executes the ditto call, instead of the Document that provides content for ditto.

                  Thus, you’ll have to set the ID manually. Here is what i suggest:
                  <?php
                  /**
                   * Convert a text with linebreaks to a html list
                   */
                  $chunk = isset($chunk) ? $chunk : false;
                  $tv = isset($tv) ? $tv : false;
                  $delimiter = isset($delimiter) ? $delimiter : "\n";
                  $docid = isset($docid) ? $docid : $modx->documentObject['id'];
                  
                  if($tv){
                  	$tvArray = $modx->getTemplateVarOutput(array($tv), $docid);
                  	if(!$tvArray[$tv])
                  		return;
                  	
                  	$text = $tvArray[$tv];
                  } else if($chunk){
                  	$text = $modx->getChunk($chunk);
                  	if(!$text)
                  		return;
                  } else {
                  	return;
                  }
                  
                  $lines = explode($delimiter, $text);
                  $out = '<ul>';
                  foreach($lines as $line){
                  	$out .= '<li>' . trim($line) . '</li>';
                  }
                  $out .= '</ul>';
                  return $out;
                  ?>
                  

                  The above snippet now has a fourth parameter called &docid which allows you to specify the desired document id (this should point to the document, that has the TV called ’listItems’). If none is specified, it will use the id of the documentObject (which is not what you want when using ditto)!

                  Now you call it in your Ditto Template as following:
                  [[ListBuilder? &tv=`listItems` &docid=`[+id+]`]]
                  

                    • 4749
                    • 623 Posts
                    Way to go! It works! After I read your post, it made sense - the docid worked like a charm!
                    Thanks Roman, I truly appreciate all the help. This is definitely worthy of the wiki!!

                    All the best,
                    cbaone

                    EDIT: Brilliant solution to a simple problem! Brilliant!
                      The MODx has you...
                      Utah Web Design
                      • 2734
                      • 165 Posts
                      Ahh. Finally.
                      Glad i could help!

                      Cheers -- roman