We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    Hi, here's my problem, I'm generating the following output and I need to get rid of the last comma:
    slides : [
    	{image : 'image1.jpg'},
    	{image : 'image2.jpg'},
    	{image : 'image3.jpg'}, // Get rid of this comma
    ]

    And here's how I'm doing it:
    [[!Gallery? 
    	&thumbTpl=`galleryThumb`
    	&toPlaceholder=`gallery`
    ]]
    
    // galleryThumb
    {image : '[[+image]]'},
    


    Any help much appreciated.
      • 577
      • 132 Posts
      I can think of several way depending on how you have other things setup and where you are pulling the data from. That said the easiest thing I can think of and have doen it several times myself is to roll-your-own output filter.

      So you would do everything the same as you have it, except you would add the output filter to your placeholder

      [[+gallery:rtrim]]


      adding rtrim and then creating a snippet called "rtrim" would then allow you to do the following.

      
      $input = $modx->getOption('input',$scriptProperties,'');
      return rtrim($input,',');
      
      


      This would then strip the right most char off the end if it is a comma [ed. note: aesmith last edited this post 14 years, 9 months ago.]
        "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
        • 34120
        • 236 Posts
        This works great, thanks for looking.

        I think I have some timing issues now, js executing before the gallery placeholder has fully loaded. I'm not sure though, I think I'll start another thread.

        Thanks

          • 577
          • 132 Posts
          It could not be the gallery itself unless you are executing the gallery through an external ajax call. The gallery placeholder along with anything MODX related is all back-end (ie: server) processes.

          Think of MODX as a big HTML generator and nothing gets sent to the browser until the HTML page is completely build. Then all HTML for the given DOM is delivered all at once. Thus all of the Gallery is in place.

          This is not to say that all images will be there because images are then a separate request after the HTML is delivered.
            "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
            • 34120
            • 236 Posts
            Ah thanks again, that hopefully eliminates my theory. The js which the gallery placeholder feeds the paths into is inline so as you say this should all be completed before reaching the browser.

            I've discovered this problem only occurs in Chrome so it's possibly not directly related.

            Much appreciated, cheers