Jump to content

taotoo

Members
  • Content Count

    8
  • Joined

  • Last visited

Community Reputation

1 Neutral

About taotoo

  1. I've been staring at this for a while and finally figured out why it works - very clever!
  2. That works great - I'll now go through your code and attempt to understand what it's doing - thank you!
  3. Thank you Robin - I could have been clearer, both page reference fields are on the Work template: work - work_exhibition - work_artist
  4. I have three types of content, with two page reference fields linking them. work / \ work_exhibition work_artist / \ exhibition artist On the Exhibition template, I want to show all artists that appear in an exhibition, and beneath each artist all works that are both by them and in the exhibition. I have the following code: <?php foreach ($pages->find("template=work, work_exhibition=$page->path") as $workIds):?> <?php foreach ($pages->find("template=artist, title={$workIds->work_artist->title}") as $artist):?> <strong><?= $artist->title; ?></strong><br> <?= $workIds->title; ?><br><br> <?php endforeach; ?> <?php endforeach; ?> Which is giving me (e.g.): Artist 1 Work Artist 1 Work Artist 2 Work I'd like it to instead show: Artist 1 Work Work Artist 2 Work I've tried using "->unique()" but wasn't sure where to put it. Or maybe I need to go about this some other way. Any pointers appreciated.
  5. Interestingly, if I remove ARTIST from the the pages.find line, and instead put it in a conditional, it then works fine. <!--Show artists that are related to current exhibition--> {% set ARTIST = page.exhibition_artist %} {% for artist in artist %} {{ artist.title }} <!--Show works that are related to current exhibition and belong to a given artist--> {% set work = pages.find("template=work, work_exhibition=[page.path]") %} {% if work.work_artist==ARTIST %} {{ work.title }} {% endif %} {% endfor %}
  6. Thanks for this - looks neater than what I came up with - I'm sure I can learn from it.
  7. Thanks - unfortunately it's still not working though. I actually managed to do it in PHP, but I thought Twig might be easier to learn. This works fine: <?php foreach($page->exhibition_artist as $a) { echo "$a->title"; /*Get works whose work_exhibition field points to the current last segment and work_artist field points to the given artist*/ $wor = $pages->find("template=work, work_exhibition=[{$page->path}], work_artist=[$a]"); /*Render works*/ foreach ($wor as $w) { foreach($w->work_image as $image) { echo "&nbsp;&nbsp;<img src='$image->url' width='200'>"; } /*Render artists*/ echo "{$w->title}"; } } ?>
  8. I'm a beginner and was wondering why the code below isn't working. The issue is where ARTIST (capitalised) appears in the code for the second time. I want it to take the value from the first mention of ARTIST, but it's not doing anything. If I replace the second instance with the name of an artist, then it displays as expected. Hopefully I'm making a basic error! <!--Show artists that are related to current exhibition--> {% set ARTIST = page.exhibition_artist %} {% for artist in artist %} {{ artist.title }} <!--Show works that are related to current exhibition and belong to a given artist--> {% set work = pages.find("template=work, work_exhibition=[page.path], work_artist=[ARTIST]") %} {% for work in work %} {{ work.title }} {% endfor %} {% endfor %}
×
×
  • Create New...