1

Please refer to this thread for information leading up to this problem.

I am having problems with mass file uploads, the files will upload in my CP for craft, and be present on the assets list, however when I come to post the entry, only one image will show on my live page.

Here is my code:

{% extends "_layout/_layout" %}

{% set bodyClass = "photos" %}

{% block metaTitle %}{{ entry.title }} Photo Gallery{% endblock %}
{% block metaDescription %}{{ entry.metaDescription }}{% endblock %}

    {% block content %}
              <div class="container">
                    <div class="page-title-heading">
                        <h1>{{ entry.title }}</h1>
                    </div>
                </div>
                <div class="title-border"></div>

        <div class="portfolio-container">
        {{ entry.body }}

        <ul id="portfolio-items-one-fourth" class="portfolio-items-one-fourth clearfix">
            {% set photos = entry.photos %}
            {% if photos | length %}
            {% for photo in photos %}
            <li class="item photo" style="display: inline-block; opacity: 1;">
                <div class="item-content">
                    <div class="link-holder">
                        <div class="portfolio-item-holder">
                            <div class="portfolio-item-hover-content">
                                {% set image = photo.uploadPhoto.first() %}
                                <a href="{{ image.getUrl('photoLightbox') }}" class="fancybox" rel="gallery" title="{{ photo.photoCaption }}">
                                    <img src="{{ image.getUrl('photoListing') }}" width="270" class="portfolio-img">
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </li>
            {% endfor %}
            {% endif %}
        </ul>
    </div>

    <p class="next-prev gallery-links">
        {% set prev = entry.getPrev({'section' : entry.section.handle}) %}
        {% set next = entry.getNext({'section' : entry.section.handle}) %}
        {% if prev %}<a href="{{ prev.url }}">&laquo; {{ prev }}</a>{% endif %}
        {% if next %}<a href="{{ next.url }}">{{ next }} &raquo;</a>{% endif %}
    </p>
    <p class="photo-credits gallery-links">
        <a href="/photo-credits">Photographer credits</a>.
    </p>

    {% endblock %}

Any help with rectifying this code would be absolutely wholeheartedly appreciated!

Thank you!

2
  • Is entry.photos a Matrix field or an Assets field? Commented Mar 25, 2015 at 8:42
  • An assets field @MatsMikkelRummelhoff
    – Harkat
    Commented Mar 25, 2015 at 8:53

1 Answer 1

3

It looks like you're trying to access another asset within your assets (asset meta field).

{% set photos = entry.photos %}

{# Loop assets of `entry.photos` as `photo` #}
{% for photo in photos %}

    {# Get first `uploadPhoto` element within `entry.photos[nth]` #}
    {% set image = photo.uploadPhoto.first() %}
    {{ image.getUrl() }}

{% endfor %}

I guess that's not what you want. Check your field handles again, you probably only need to do this.

{% set photos = entry.photos %}

{% for photo in photos %}
    {{ photo.getUrl() }}
{% endfor %}

If 'uploadPhoto' is an asset source and you allow users to upload to multiple sources, but only want to loop assets from 'uploadPhoto' in your template, you would do this like so.

{% set photos = entry.photos.source('uploadPhoto') %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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