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

Adding file upload to “modular” template in GRAV

Started by Zkisly 8 years ago · 3 replies · 724 views
8 years ago

I'm using a theme that use background image in template like this:

TWIG
{% if page.header.background_image != '' %}
    {% set background_html = 'style="background-image: url(' ~ page.media.images[page.header.background_image].url ~ ');"' %}
{% else %}
    {% set  background_html = "" %}
{% endif %}

In other page templates (in admin) I can see upload field, but not in modular - I see only title and order of modules.

I want to take advantage of image upload, but I can find place to put them, nor add it in the modular.yaml in the theme (I don't want to edit modular from the grav installation).

My goal is to edit theme in the manner where I can use the image upload.

8 years ago

If I'm understanding you correctly, you can access the parent page object from your modular template. Like this using your example:

TWIG
{% if parent.page.header.background_image != '' %}
    {% set background_html = 'style="background-image: url(' ~ parent.page.media.images[parent.page.header.background_image].url ~ ');"' %}
{% else %}
    {% set  background_html = "" %}
{% endif %}

8 years ago

If themes does not provide a modular.yaml file, it will use the one provided by antimatter, which seems to be the case with your theme. This modular.yaml does not provide a pagemedia field which allows you to add medias.

Thus, you only have two solutions:

  • Add your own modular.yaml file in themes/yourtheme/blueprints folder and add a pagemedia field
  • Add your media manually via ftp

Hope it helps

Paul

8 years ago

Find the name of the image file using the developer tool in Chrome Firefox or Safari. Start searching for this file on your computer, limiting the search space to the project folder. So you will find the folder.

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