Adding file upload to “modular” template in GRAV

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

{% 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.

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

{% 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 %}

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

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.