Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Image displays alt text - image itself not visible

Started by Paweł 7 years ago · 4 replies · 570 views
7 years ago

Hi,

I have a problem with dispalying an image. Image is in the same folder as feature.md file.
The code in the header of feature.md is:

YAML
    title: 'some title'
    cache_enable: false
    features:
        -
            header: 'some header'
            text: 'some text'
            image: wykres.png
        -
            header: 'anotherheader'
            text: 'another text'
            image: wykres.png
    ---

And this is code from my modular template file features.html.twig:

TWIG
    {{ content }}
    <div class="feature-items">
    {% for feature in page.header.features %}
           <div class="feature">
            {% if feature.icon %}
            <i class="fa fa-fw fa-{{ feature.icon }}"></i>
            <div class="feature-content icon-offset">
            {% else %}
            <div class="feature-content">
            {% endif %}
            {% if feature.header %}
            <h4>{{ feature.header }}</h4>
            {% endif %}
            {% if feature.text %}
            <p>{{ feature.text }}</p>
            {% endif %}
            {% if feature.image %}
            <img src="{{ feature.image }}" alt="" width="100" height="100">
            {% endif %}
            </div>
        </div>
    {% endfor %}
    </div>
</div>

and as a result I get only alt text instead of image, what might be a problem?

last edited 07/03/19 by Paweł
7 years ago

Hello,

You could dump feature.image to see if you get the correct path.

TWIG
{{ dump( feature.image ) }}
7 years ago

@AmauryH this command gives me null, but anyway thank you, I managed to display images with:
{% if feature.image %} <img src="{{ page.media[feature.image].url }}" alt=""> {% endif %}

7 years ago

Hey @AmauryH I've found the same thing, dump doesn't output anything for me. I've had much better luck with print_r so something like this might work for you:

TWIG
<pre>
  {{ feature.image|print_r }}
</pre>

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 53 9 hours ago
Support · by Anna, 3 days ago
2 59 12 hours ago
Support · by Justin Young, 13 hours ago
1 30 13 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago