Iām moving my portfolio website from HTML files (and no CMS) to Kirby. I currently have all my images, for all the website, in one folder. I like the simplicity of this and being able to check all the images file sizes, or optimise all the images in one go, without having to open lots of different folders.
Is it possible in Kirby to put all the images and assets (PDFs etc) in one place, or will this create issues?
Shouldnāt be a problem, just point your files sections to a single parent. That parent would the contain all files.
Something like:
sections:
files:
label: All my files
type: files
parent: site.find('filestore')
Then, have a filestore folder in your content folder and put everything there. (the name "filestore" is arbitrarily chosen, it could be anything).
Maybe also put a ānope.txtā in that folder, then create an empty nope.php template, just to make sure people donāt try to access āwww.yourwesbite.com/filestoreāā¦ ("nope" was also arbitrarily chosen)
Maybe also put a ānope.txtā in that folder, then create an empty nope.php template, just to make sure people donāt try to access ā[www.yourwesbite.com/filestore](http://www.yourwesbite.com/filestore)āā¦
why would someone try to access this folder? So the folder filestore is also a web page someone could visit? What would they see or be able to do?
There isnāt really a good reason someone would try to access it.
Itās just that the files will ultimately be served under /media/pages/filestore/<somehash>/myimage.jpg, indicating that there is a filestore page.
If you then have some default template that gets applied to the filestore, you might do stuff in that default template to the page that you donāt really want.
Setting the template of filestore to ānopeā, and having an ānopeā template, makes it so that if someone tries it, he just gets an empty page.
Any folder is a page accessible through the browser.
Okayā¦ so I canāt simply have a folder, perhaps called āresourcesā where I put all my images, without this becoming a web page www.xyz.com/resources
But where is the problem with simply blocking access to the page with the files?
Unless you are using the same file in multiple locations, Iād store them with the page they belong to, anyway, instead of in one central space.
Another option would be to store the files directly in the content folder (next to site.txt) as files of the $site object. Then you wouldnāt need a special page folder.
But where is the problem with simply blocking access to the page with the files?
Why would I need to bother to block access to the āresourcesā folder/page?
How can I block access to this page?
Unless you are using the same file in multiple locations, Iād store them with the page they belong to, anyway, instead of in one central space.
Argh, yes this could be an issue. Some images are used on different pages. So would this mean that I would be best off storing all my images in one folder?
Another option would be to store the files directly in the content folder (next to site.txt) as files of the $site object. Then you wouldnāt need a special page folder.
There are hundreds and I think this would make my content folder very messy and hard to find stuff?
What @rasteiner already suggested, by using a template which sends users to the error page if they happen to open this link.
Use a route that does the same (no template needed)
It depends. If itās just a few duplicate files, I personally wouldnāt worry and just upload them again to different places. Or do a mixture, upload files that are used multiple times to the site object, all others to the pages they belong to.
After all, searching through hundreds or thousands of images could also become a bottleneck.
I was wondering what that suggestion meant! So I create a nope.txt in that folder, then create an empty nope.php. So what do I write in the nope.txt file? What does an empty nope.php file mean? Literally with no code, blank file?
As many of my images are used on multiple pages (and because I think it is neater) all my images are in one folder called āresourcesā.
I can create relative links to my images, which works fine, until I have child pages (/portfolio/case-study1), then the relative link obviously doesnāt work.
I donāt really want to create different relative links to images depending on where the page is in my site and absolute URLs while I am building the site locally is a total pain, so how do you link to images?
I guess the same problem is true with links between pages. Child pages would need a different relative link to parent pages?
We always use Kirbyās API to access the URL of pages and files:
<?= $page->url() ?>
<?= $file->url() ?>
The question is now if you have all files in one folder, how do you want refer to your files in your content. In a textarea field, in a blocks field, in a select field?
We always use Kirbyās API to access the URL of pages and files:
What does that mean?
In my header I have a logo. How do I link to my logo image? So that the same link works on all pages regardless of whether the page is a parent or a child?
So if your site will always be directly in the web root, that works.
If, however, at some point you decide to move this site to a subfolder, like from www.mark-e.com to www.mark-e.com/archive, this will no longer work because it will try to load images from www.mark-e.com/resources instead of www.mark-e.com/archive/resources.
Kirby however always knows where it was installed. Thatās why you could use:
Nevertheless, the problem I see with this approach is that you usually probably will not want to hard-code (i.e. manually write ) your files names into your template (unless you want to output a gallery or something like that). Usually, your files would probably be included in your text or selected in a field, then rendered in your template from there?