[[+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.
<a href="[[~[+id]]]" title="[[+pagetitle]]"><img src="[+Art Image]" alt="[+pagetitle]" /></a>
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>
<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>
<figure class="featured col-sm-6 col-md-3"> <a href="[[~[+id]]]]" title="[[+pagetitle]]"><img src="[[+tv.art_image]]" alt="[[+pagetitle]]" /></a> </figure>
<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>
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.