1

To expand upon How to get the previous or next two entries I was wondering how I can also add the image and an input from each entry.

I have simplified the html-structure in this example but essentially what I want to add is: entry.portfolioImage.one and row.kundenavn from row in entry.kunde.

The links and entry title is working.

{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('portfolio').order('title desc') %}

{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

{# And make sure to only output the links if the element exists #}
{% if prevEntry %}
  <a class="project" data-type="image" href="{{ prevEntry.url }}">
    <img
      src="{{ entry.portfolioImage.one().getUrl('progressivePortfolio') }}"
      data-src="{{ entry.portfolioImage.one().getUrl() }}"
    >
    <h3>{{ prevEntry.title }}</h3>
    <div class="project-client pink bold">
      {% for row in entry.kunde %}
          {{ row.kundenavn }}
      {% endfor %}
    </div>
  </a>
{% endif %}
{% if nextEntry %}
  <a class="project" data-type="image" href="{{ nextEntry.url }}">
    <img
      src="{{ entry.portfolioImage.one().getUrl('progressivePortfolio') }}"
      data-src="{{ entry.portfolioImage.one().getUrl() }}"
    >
    <h3>{{ nextEntry.title }}</h3>
    <div class="project-client pink bold">
      {% for row in entry.kunde %}
          {{ row.kundenavn }}
      {% endfor %}
    </div>
  </a>
{% endif %}
2

Bratvold, what do you mean with "input"?

Actually, if you can get the title of your prev-item, you can get everything of it.

{% if prevEntry %}
  <a class="project" data-type="image" href="{{ prevEntry.url }}">
    <img
      src="{{ prevEntry.portfolioImage.one().getUrl('progressivePortfolio') }}"
      data-src="{{ prevEntry.portfolioImage.one().getUrl() }}"
    >
    <h3>{{ prevEntry.title }}</h3>
    <div class="project-client pink bold">
      {% for row in prevEntry.kunde.all() %}
          {{ row.kundenavn }}
      {% endfor %}
    </div>
  </a>
{% endif %}
| improve this answer | |
  • Thanks for the reply! prevEntry worked great for the images but not the other part. This part comes up empty: {% for row in prevEntry.kunde.all() %} {{ row.kundenavn }} {% endfor %} – Stig Melón-Bratvold May 26 at 18:42
  • What type of field is kunde? Matrix? Table? – RitterKnight May 26 at 19:53
  • If "kundenavn" is an entries selection field, you need to loop again. {% for entry in row.kundenavn %}{{ entry.title }}{% endfor %} – Marten Brosch May 27 at 8:44
  • Thanks @MartenBrosch :) – Stig Melón-Bratvold May 29 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.