How can I keep same folder's name when I publish a page

That a real problem for me to use the visible/unvisible feature :
When I publish a page, Kirby add to his folder’s name a numbler of his placement in the menu as prefix.
It’s a problem for my images urls who changed to in my page and all my subpages.
Do you have any solution for that?
Thanks in advance

See this post (and a few more characters)

Have you tested yourself?
I currently use $section->url() but when I remplace by your solution, it’s doesn’t works, like… the page content stop to load after this attribut. :confused:

No, I haven’t tested it myself. How do you embed your images? What version of Kirby do you use?Could you post your complete code? And what error message do you get? Pls. check your php error logs.

I use a little plugin to have a modular interface (
So in my template file, where the content have to be, I have a foreach for the builder plugin :

<?php foreach($page->builder()->toStructure() as $section): ?>
    <?php snippet( snippet('sections/' . $section->_fieldset(), array('section' => $section)) ) ?>
<?php endforeach ?>

And then I have a template file for the “image module” where basicely I have :

<img src="<?php echo $section->url() ?>" alt="Section image" />

Otherwise I use Kirby 2.1

Does that help you? :grimacing:

Not quite. So $section->url() is your image url?

Judging from the plugin docs, you should currently have something like this:

<img src="<?php echo $section->picture()->toFile()->url() ?>" alt="section image">

Which then should be changed to sth like this:

$image = $section->picture()->toFile(); // replace "picture" with name of your image field
<img src="<?php echo $image->page()->url() . '/' . $ image->filename() ?>" alt="section image">

Not tested, though.

But as @lukasbestle mentioned in the post I quoted above, this is not recommended, because you will get a redirect whenever the file is accessed.

The problem is not of the plugin, who show the right url that the admin paste himself on a field ( ).
The problem is when I publish a page, his url change, so It’s no more working because I manually enter the image url (sorry, hard to explain)

Ok, I see what you mean. Why does the admin have to enter a fixed URL, then, instead of just the (relative) path to the file or just the filename?

Yeap, could be a good solution if the path have to change when it’s published or not.

But there is a problem with this solution, I can’t use the web url for the path (mywebsite/mypage/mysubpages/myfile.jpg) because there aren’t the number problem on urls (thanks to url rewriting) the number prefix (42-mypage) are on the folders names in /content. Do you have an idea to get the file path ?

Well, the redirect solution would only be useful for SEO purposes, but in your case, you don’t want to release your page to the public before it is being published.

The best solution would be a select field that fetches all images from the folder, instead of manually typing the path, if that fits into your workflow.

I found the the $file->url() function who works pretty well, but I would have the same url without the file name (to permit to the admin to enter the file name manually

Where are the images the admin is supposed to enter into the form, in the same folder and can they be just anywhere?

Let´s suppose your admin just enters the filename of an image, e.g. “myimage.jpg” and the field is called “my image”.

If it is an image from the folder of the page, you can fetch it like this:


If the image can be anywhere on the site:

$site->index()->files()->findBy('filename', $page->mycover())->url();

The images will be in the same folder, but there are severals yeah :slight_smile:
The admin is suppose to enter just the file name (like “myawesomeimage.jpg”)

There is that in the bleuprints file :

        label: Linked Image
        entry: >
          <img src="{{_fileUrl}}/{{imgname}}" height=300px/></br>
          Image name: {{imgname}}
            label: Link Url
            type: text

The admin enter the file’s name in {{imgname}} field, and it’s works pretty well ( ).

Then you should be able to use the code from above:

<?php echo $section->imgname()->toFile()->url() ?>

Hm It should works, but It seems fail, the page loading stop at the moment where It should load the url.

What error message do you get? BTW: could you pls. use three backticks to highlight blocks of code? Makes it a lot easier to read …

Where can I get a debug code ? Is there a embeddedin debug mode in Kirby?

Sorry about that, i used the “formatted code” button from the markdown wysiwyg editor.

No problem, single backticks are for inline code, three for code blocks.

The variable is probably wrong, could you post the code from the snippet that outputs the image stuff?

To enable debug, set debugging to true in your config.php:

c:: set('debug', true);

You can also check out the server error logs.

How thanks for the debug and how to paste code tips !
I have now this error :

on line 3

My file linkedImage.php contain :

<div class="imagecontent">
    <img src="<?php echo $page->file()->url(); ?>" alt="Section image" /><br/>
    <?php echo $section->imgname()->toFile()->url() ?>

And my blueprints file contain :

        label: Linked Image
        entry: >
          <img src="{{_fileUrl}}/{{imgname}}" height=300px/></br>
          Image name: {{imgname}}
            label: Image name
            type: text