Out put file url inside Kirby panel based page

Hello,

Recently I came across TimOetting’s builder plugin and noticed he’s using a file url variable: {{_fileUrl}} within the blueprints to out put image urls inside the panel. This is a simple but powerful aspect of his plugin.

I have a number of sites using a file selector field and was wondering if there is any way of achieve the same result or how I would possibly go about recreating this variable to work beyond the builder plugin?

I’ve seen many people suggesting the “Visual file selector plugin” however it seems to output every single image multiple times.

Any help is appreciated.

Like so:

Images: 
label: Images
type: structure
entry: >
  <img src="{{picture}}" />
fields: 
  picture:
    label: Picture
    type:  select
    options: query
    query:
      fetch: files
      value: '{{url}}'
      text: '{{filename}}'

<3

2 Likes

I used that technique too, but the problem for me is that I work on several servers. One localhost for developing, one demo-server and the final live server. If I use {{url}} as the value and save the page on my local machine Kirby store the local url in the content file, which of course doesn’t work when I move the site to the demo and live server and it tries to display an image located at http://localhost:8888/image-file-name.jpg.

How can I solve this?

Generally it is recommended to save only the filename (meaning value: '{{filename}}') to make the value independent from server name and the URI of the page.

Currently it is not possible to output something else than the stored value using the entry option of the structure field. You could create a copy of the field in your site/fields directory and modify it so that the placeholder gets the URL from the file object instead of returning the stored value.

That would be a very nice entry feature for the structure field in the future! Hope this will happen…

There is a suggestion over here about this with a temporary solution.