1

I am new to Craft and have a decent handle on the basics, but I am struggling a little getting this to work. Here is what I would like to do:

I have a banner with bxslider which will be looping through images in a matrix field. This is for a church site and this template will be used for all their ministries. Each ministry will have it's own photos, but right now assets is returning images for all entries.

Here is my code:

{% elseif craft.request.segment(2) == "crosstrainers" %}

<div class="banner-slider-block">

    <ul class="banner-slider-list">

        {% for entry in craft.entries
            .section('site_content')
            .find() 
        %}

        {% for block in entry.slider %}     
        <li>

            <div class="banner-slide-block">

                    {% for image in block.sliderImage.limit(1) %}
                        <img class="slider-image" src="{{ image.getUrl }}" alt="{{ entry.title }}" />
                    {% endfor %}

                    <div class="page-wrapper">

                        <div class="slider-text-box {{ block.sliderTextBoxLocation }}">

                            <h3 class="slider-header">{{ block.sliderHeader}}</h3>

                            <p class="slider-text">{{ block.sliderText}}</p>

                            <a class="slider-button" href=""><div class="linked-button">{{ block.sliderButtonText}}</div></a>

                        </div>

                    </div>          

            </div>

        </li>
        {% endfor %}

        {% endfor %}

    </ul>

</div>

Any suggestions on how to limit the asset results to each ministry.

1
  • are you trying to get the first image from an asset field? are you looking for this? {% set image = block.sliderImage.first() %}{{image.url}} Jun 25 '15 at 15:33
1

From your example, it is a bit hard to tell how your site is organized, but it sounds like you want to set up content specific to each ministry (which is stored in the top-level of your "site_content" structure?), which will be shared across all of that ministry's sub-pages. Regardless, you will essentially want to retrieve the entry where the slider data is stored, and loop through the matrix data from there.

{% if craft.request.segment(2) == "crosstrainers" %}
    {% set entry = craft.entries.section('site_content').slug('crosstrainers') %}
    {% for block in entry.slider %}
        {# prevent error if no slider image is defined #}
        {% if block.sliderImage|length %}
            {% set image = block.sliderImage.first() %}
            <img class="slider-image" src="{{ image.getUrl }}" alt="{{ entry.title }}" />
            ...
        {% endif %}
    {% endfor %}
{% endif %}
1
  • Douglas, thank you. I didn't give you enough information, sorry about that, but you did help me see what I was doing wrong. Working perfect. Thank you again. Jun 25 '15 at 19:38

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.