We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52024
    • 15 Posts
    It goes w/o saying that I don't know what I'm doing.

    I have a art gallery website editart.ch). The 4 images under the slider I put there manually. I want to create a loop to do this instead.

    I created a new checkbox TV called FeaturedWork, and checked the box for 4 images.

    I wrote the code below (simplifying for clarity), but it doesn't work. Please help.

    [[+tv.FeaturedWork:isnot=``:then=`
    	
    	for ($i= 0; $i < 4; $i++) {                
                  
    	<figure>
    	    <a href="[[~[+id]]]" title="[[+pagetitle]]"><img src="[+Art Image]" alt="[+pagetitle]" /></a>
    	</figure>
    	}
    
    `]]

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

      • 42562
      • 1,145 Posts
      What in particular does not work? What shows and what does not?

      For a start, +pagetitle and +Art Image have insufficient brackets
      <a href="[[~[+id]]]" title="[[+pagetitle]]"><img src="[+Art Image]" alt="[+pagetitle]" /></a>
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 52024
        • 15 Posts
        Quote from: donshakespeare at Oct 11, 2016, 09:04 PM
        What in particular does not work? What shows and what does not?

        For a start, +pagetitle and +Art Image have insufficient brackets
        <a href="[[~[+id]]]" title="[[+pagetitle]]"><img src="[+Art Image]" alt="[+pagetitle]"></a>

        Yes, I fixed that -- the insufficient brackets -- after I posted the code. Sorry. Nothing show on the home page where I put it:

        <div class="row">
             <div class="col-xs-12 col-sm-offset-1 col-sm-10">
        
        		[[+tv.FeaturedWork:isnot=``:then=`
        	
        	      for ($i= 0; $i < 4; $i++) {                
                      
        	      <figure class="featured col-sm-6 col-md-3">
        	    
                               <a href="[[~[+id]]]" title="[[+pagetitle]]"><img src="[[+Art Image]]" alt="[[+pagetitle]]" /></a>
        	     </figure>
        	}
        `]]
            </div>
        </div>
        
          • 44195
          • 293 Posts
          Hi it looks like you're putting PHP code directly into the template there...

          I assume each artwork is a child resource of the current resource?
          e.g.
          currentResource
          |
          -- paintingResource1
          |
          -- paintingResource2
          |
          -- paintingResource3
          |
          -- paintingResource4

          You also need a TV called art_image and it should be added to the template each paintingResource uses.

          If so, you could write a snippet to display them or just use a tool suited to the job such as getResources or pdoTools.
          Let's use getResources this time so go and install it via the package manager.

          Once that's done, create a chunk. We'll call that 'paintingChunk'.

          Copy and paste this into your chunk:
          <figure class="featured col-sm-6 col-md-3">
              <a href="[[~[+id]]]]" title="[[+pagetitle]]"><img src="[[+tv.art_image]]" alt="[[+pagetitle]]" /></a>
          </figure>
          

          and then save it. Note that I changed [[+Art Image]] to [[+tv.art_image]] otherwise it won't work.

          Now in your original template (the one you showed above and is attached to the parent resource).

          Add the following getResources call into it:

          <div class="row">
               <div class="col-xs-12 col-sm-offset-1 col-sm-10">
           
                  [[+tv.FeaturedWork:isnot=``:then=`
                      
                      [[getResources?
                          &parents=`[[*id]]`
                          &tpl=`paintingChunk`
                          &includeTVs=`1`
                          &processTVs=`1`
                      ]]
          
                  `]]
              </div>
          </div>
          


          This will then get each of the paintingResources and load the paintingChunk for each one. It will put the values into the placeholders in the chunk for each different painting.
            I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
            Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
          • discuss.answer
            • 52024
            • 15 Posts
            Quote from: muzzstick at Nov 22, 2016, 07:33 AM
            Hi it looks like you're putting PHP code directly into the template there...

            I assume each artwork is a child resource of the current resource?
            e.g.
            currentResource
            |
            -- paintingResource1
            |
            -- paintingResource2
            |
            -- paintingResource3
            |
            -- paintingResource4

            You also need a TV called art_image and it should be added to the template each paintingResource uses.

            If so, you could write a snippet to display them or just use a tool suited to the job such as getResources or pdoTools.
            Let's use getResources this time so go and install it via the package manager.

            Once that's done, create a chunk. We'll call that 'paintingChunk'.

            Copy and paste this into your chunk:
            <figure class="featured col-sm-6 col-md-3">
                <a href="[[~[+id]]]]" title="[[+pagetitle]]"><img src="[[+tv.art_image]]" alt="[[+pagetitle]]"></a>
            </figure>
            

            and then save it. Note that I changed [[+Art Image]] to [[+tv.art_image]] otherwise it won't work.

            Now in your original template (the one you showed above and is attached to the parent resource).

            Add the following getResources call into it:

            <div class="row">
                 <div class="col-xs-12 col-sm-offset-1 col-sm-10">
             
                    [[+tv.FeaturedWork:isnot=``:then=`
                        
                        [[getResources?
                            &parents=`[[*id]]`
                            &tpl=`paintingChunk`
                            &includeTVs=`1`
                            &processTVs=`1`
                        ]]
            
                    `]]
                </div>
            </div>
            


            This will then get each of the paintingResources and load the paintingChunk for each one. It will put the values into the placeholders in the chunk for each different painting.

            Thank you. That's what I did in the end. It took me a while but I finally got there. And thanks again for contributing this. It confirmed that I was on the right track.

            Gary
              • 44195
              • 293 Posts
              Good stuff. Glad it's working smiley
                I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
                Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com