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.

Themes & Styling

Access media made from a blueprint of type:file

Solved by Ace A. View solution

Started by Ace A. 4 years ago · 1 replies · 277 views
4 years ago

I have defined the following in my blueprints.yaml

YAML
        media: # load user assets for the theme
          type: tab
          title: Media
          fields:
            custom_favicon:
              type: section
              title: Custom Favicon
              fields:
                media.favicon:
                  type: file
                  label: Upload your custom favicon
                  destination: 'theme://assets/user_favicon/'
                  multiple: false
                  avoid_overwriting: yes
                  limit: 1
                  filesize: 1
                  accept:
                    - image/*

It works. I was able to upload a file that generated the following yaml markup

YAML
media:
  favicon:
    user/themes/canvas/assets/user_favicon/android-chrome-512x512.png:
      name: android-chrome-512x512.png
      full_path: android-chrome-512x512.png
      type: image/png
      size: 11710
      path: user/themes/canvas/assets/user_favicon/android-chrome-512x512.png

all the user-made attributes can be accessed if I dumped theme_config.media.favicon. But I cannot access the path of the uploaded image with an url() filter or a dot notation i.e. {{ theme_config.media.favicon.path }}. I am lost as to which I got wrong here. Is my blueprints malformed or am I using the wrong dot notation?

Please help. thanks.

4 years ago Solution

Solved. this solution is based on Quark's logo partials.

TWIG
{# extract the media array #}
{% set favicon = theme_config.media.favicon %}

{# assign the uploaded file name to a variable #}
{% set favicon_file = (favicon|first).name %}

{# append the filename to the intended source url #}
{{ url('theme://assets/user_favicon/' ~ favicon_file) }}

last edited 12/10/22 by Ace A.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 93 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago