I have added an image into the folder /content/home and I would like to reference this in home.txt in the same folder. Is this the best way to store and reference images using kirby?
HTML (./site/templates/home.php)
<div class="row" style="background-image:url(<?php echo $page->HeroBackground() ?>)">
</div>
(./site/blueprints/home.yml)
HeroBackground:
type: files
headline: Cover Image
max: 1
template: cover
(./content/home/home.txt)
HeroBackground: ./img.jpg
----
HeroBackground: img.jpg
Use just the filename for files in the same folder.
can this image then be changed in the backend? Is it dynamic?
@pixelijn I am getting this error now: GET http://localhost/img.jpg 404 (Not Found)
I have updated the question with more code.
You have to create a file object from the field value first useing thetoFile()
page method.
Note that if you want to use a files field in the Panel, you have to store your files in yaml format in the content file.
thanks for the help, do you have some example code, i do not understand what you mean?
For a single file: https://github.com/getkirby/starterkit/blob/master/content/1_photography/1_trees/album.txt
For multiple files:
Cover:
- monster-trees-in-the-fog.jpg
- monster-trees-in-the-rain.jpg
- monster-trees-in-the-sun.jpg