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

Images on sub-pages not working

Started by Muut Archive 11 years ago · 7 replies · 1086 views
11 years ago

Hi everybody!
I just created a page with the following structure:

01.home
-> 01.test

When I now place a image in the 01.home/default.md with <img src=images/demo.png> it is working.

Using the same code in the 01.home/01.test/default.md, the image does not show up on this page! Are there any dependencies missing?

Thx!

PS: I`m using the antimatter-theme without any changes.

11 years ago

Where did you put the demo.png image? Generally images are put in the same folder as the .md file. This associates them with the page.

For example if you have:

YAML
pages/01.home
  - default.md
  - demo.png

Then you can reference that image directly with ![](demo.png) (using markdown is the preferred approach).

You can even access this image from a sub-page pages/01.home/01.subpage/default.md with: ![](/home/demo.png)

However, if you want to access an image from multiple locations, you can put all the images into an empty image page like:

YAML
pages/01.home
 - default.md

pages/images
 - demo.png

Then you can access that image from any page with the ![](/images/demo.png) where image/ is actually a slug to the images page.

Note, you should really use these markdown image tags because they have support for the logic to find the image in a pages. The logic is the same as is outlined in this document about links.

11 years ago

Thank you very much, worked fine! I thought, all images should be stored in the /grav/images/ folder ...

11 years ago

No Grav's /images/ folder is for cached folders only. You shouldn't put anything in there yourself. The rule of thumb is that any thing the user adds should be in the /user/ folder only.

11 years ago

I see. And where, in this case would be the right folder for the favicon? /grav or webdirectory-root?

11 years ago

Generally we put the favicon in the theme itself as you need to have the reference directly in the theme anyway.

TWIG
<link rel="icon" type="image/png" href="{{ url('theme://images/favicon.png') }}" />

This is the new way to do it.. it will look in the theme's images/ folder so: user/themes/antimatter/images/favicon.png will be used.

11 years ago

Thanks, this also worked fine! :-) GRAV rocks, I need some practice, though I keep on learning!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1368 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago