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.

General

How do add a Background Image in Grav?

first-time

Started by Donald J. Trump 8 years ago · 7 replies · 5848 views
8 years ago

I know it seems like a simple question but I can't seem to find a way to do it.

I have the theme "gateway" installed:
https://github.com/getgrav/grav-theme-gateway

For some reason, the heading image doesn't appear it should be, by default, of a mountain...
image|690x316

In addition to this, how would I go about editing the "some text widget" paragraph seen in the picture?

Thanks

8 years ago

@DonaldTrump I haven't worked with Gateway but did take a look for you...

  • Header image not shown
    Did you install the skeleton or the theme only? The skeleton is working perfectly OK, but I can imagine the theme alone does not. It is missing the definition of the image to be displayed.

    When looking at the templates '/user/themes/gateway/templates/partials/header.html.twig' and 'header_alt.html.twig', the url of the background image is defined as:

    TWIG
    line 4: url( '{{ theme_url }}/img/{{ site.header.background }}' )
    

    This means the template searches for an image in the '/img/' folder in the template's path and looks for the filename in property 'header.background' which is being defined in file '/user/config/site.yaml`

    The file 'site.yaml' is created by the skeleton, but not by the theme. So, if you have installed the theme only, you can add the definition for the background image manually by setting the following in '/user/config/site.yaml':

    YAML
    header:
    background: background.jpg
    
  • Editing the 'Some Text Widget'
    The text for this 'widget' is hardcoded (...) in template '/user/themes/gateway/templates/partials/sidebar.html.twig', line 19. You can edit the template yourself and change the hardcoded text.

    Although it is not likely that the theme will be updated by the authors, changes you make to a template can best be done in an inherited theme. If not, you risk loosing your changes when the themes does get updated.

Again, I haven't worked with Gateway myself, but this is what I found sofar looking at the code.

Hope this helps.

last edited 11/22/18 by pamtbaau
8 years ago

@donaldtrump I have added a little advise in my answer:

Although it is not likely that the theme will be updated by the authors, changes you make to a template can best be done in an inherited theme. If not, you risk loosing your changes when the themes does get updated.

8 years ago

Thanks, I am currently trying to add a custom hero image but I'm not sure where to put the file.

I understand that I have to put: hero_image: <NAME>in the YAML file but I'm not sure where this YAML file is and I don't know where to put my image with the custom name.

Could you help me?

Thanks.

8 years ago

@DonaldTrump Using your <NAME> as filename for the background image, the following files/locations should be used:

  • The reference to the image file should be defined in '/user/config/site.yaml', using:
    YAML
    header:
    background: <NAME>
    
  • The image file itself should be located in folder: '/user/themes/gateway/img/<NAME>'

By the way, a lot more is defined in '/user/config/site.yaml' and used by the theme. You might consider downloading the skeleton for Gateway and have a look at it.

Hope this helps.

last edited 11/22/18 by pamtbaau
8 years ago

@pamtbaau:
header: background: <NAME>

Hello pamtbaau,

Thank you for trying to help me.

I still can't seem to get it to work! My "user/config/site.yaml" looks like this:

YAML
title: Cherrie
default_lang: en
author:
  name: Cherrie
  email: d[email protected]
taxonomies:
  - category
  - tag
metadata:
  description: 'Grav is an easy to use, yet powerful, open source flat-file CMS'
summary:
  enabled: true
  format: short
  size: 300
  delimiter: '==='
blog:
  route: /blog
header:
  background: hero-bg.jpg

I'm not using the Gateway theme anymore by the way.

My homepage just shows a hero white page with text.

My "user/themes/quark/images" directory looks like this:

image|452x309

Thanks.

8 years ago

@DonaldTrump It's not necessary to change the 'SOME.TEXT.WIDGET' in ... sidebar.html.twig.

The best way is to make use of the »/user/themes/mytheme/languages.yaml« file to change the text to be displayed. If it is not yer there, copy from you main theme (in my case: /user/theme/Antimatter/languages.yaml)

Hope that helps.
Kind regards

Same is valid for the SEARCH and the ARCHIVES plugins.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 95 15 hours ago
General · by pamtbaau, 20 hours ago
1 61 19 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 356 5 days ago
General · by Duc , 6 days ago
3 44 6 days ago