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

I can't call an image uploaded from Twig

Solved by Hugh Barnes View solution

Started by Pedro M 2 years ago · 2 replies · 186 views
2 years ago

The scenario is the following: I want to make a list of members of a website that will be displayed in the footer. Each member has a name, a title, and an image, which is uploaded from Grav to a destination folder inside /user/images/team.

Well, I DON'T KNOW HOW TO CALL that image within the For loop that I make for each member. This is what I have so far.

Theme YAML code:

YAML
team:
   -
     name: Pedro
     description: 'Web developer'
     image:
       user/images/team/60596353.png:
         name: 60596353.png
         full_path: 60596353.png
         type: image/png
         size: 36463
         path: user/images/team/60596353.png

Twig code:

TWIG
{% if theme_config.team is not empty %}
     <div class="team">
         {% for item in theme_config.team %}
         {% set member_image = item.image %}
         {% set member_file = (member_image|first).name %}
         <article>

             <span class="image"><img src="{{ url('user://images/team' ~ member_file) }}" alt=""></span>
             <p>
                 <strong class="name">{{ item.name }}</strong>
                 <span class="title">{{ item.description|raw }}</span>
             </p>
         </article>
         {% endfor %}
     </div>
     {% endif %}

The HTML output shows:

HTML
<span class="image"><img src="" alt=""></span>

Where this error?. Why can't I call that image the same way I call, for example, the website logo?

2 years ago Solution

@pmoreno:
url('user://images/team' ~ member_file)

Looks like you are missing a slash there.

👍 1
2 years ago

Thanks @hughbris for your answer. Finally it was nonsense, and you are right in that slash. Good observation

Thank you so much

👍 1
last edited 01/09/24 by Pedro M

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 128 20 hours ago
General · by pamtbaau, 1 day ago
1 89 1 day ago
General · by Andy Miller, 2 days ago
0 73 2 days ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago