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

How Do I Reference an Image in Theme Config?

Started by Muut Archive 9 years ago · 3 replies · 923 views
9 years ago

I'm using the Developer theme as a starting point.
http://themes.benjamin-regler.de/developer

I've created a user/config/themes/developer.yaml file.

profile:
name: "New Name"
desc: "New Description"
avatar_url: "../../pages/images/headlogo.svg"

Name and description changes the page as I want, but I cannot get my logo to replace the image that is there.

I've also edited user/themes/developer/templates/default.html.twig

<img class="profile-image img-responsive pull-left img-circle" src="{{ theme_config.profile.avatar_url }}" alt="{{ theme_config.profile.name | default(site.author.name) }}" height="180" />

I guess I just don't know the relative path to the file. "../../pages/images/headlogo.svg" obviously is wrong. "../pages/images/headlogo.svg" doesn't work either.

I found a way to get around this by using this src="{{ base_url }}/user/pages/images/headlogo.svg" in my default.html.twig file, but that does not satisfy my curiosity, nor am I sure that is the best way.

9 years ago

Note: my underscores are not showing up in the above post, I hope that does not lead to too much confusion.

9 years ago

frankly i would do this:

TXT
avatar_url: headlogo.svg

Then in my twig do this as you are already storing the image under a page called images:

TWIG
{% set avatar_image = themeconfig.profile.avatar_url %}
{% set avatar_url = page.find('/images').media[avatar_name] %}
{% set avatar_name = themeconfig.profile.name | default(site.author.name)
<img class=“profile-image img-responsive pull-left img-circle” src=“{{ avatar_url }}” alt=“{{ avatar_name }}” height=“180” />
9 years ago

I figured out I could do this:

TWIG
<img src="{{ base_url_relative }}/user/pages/images/logo.svg" alt="logo" height="100" />

no need to mess with the yaml file.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1318 9 years ago
Archive · by Muut Archive, 9 years ago
2 915 9 years ago
Archive · by Muut Archive, 9 years ago
2 4044 9 years ago
Archive · by Muut Archive, 9 years ago
1 2920 9 years ago
Archive · by Muut Archive, 9 years ago
3 1104 9 years ago