Hi folks, new Kirby user here. I’m mostly a visual designer so what I’m asking might be totally daft, but I tried combing the docs & forum posts and having a hard time finding what I need.
I’m confused as to how one can select an image for a page. Coming from a Wordpress background, I would have a custom field for a page/post that allows you to add an image from its Media section. I’m not expecting 1:1 functionality, obviously, but I don’t see any way to create a field for images much in the same way you have a field for text, tags, etc. About the only way I see to populate a page with an image is to hard code it in the php file.
I saw that but wasn’t understanding it, and it might be overkill for what I need. I’m just doing a simple site, and may want to update the image a while down the road, but it just seems like the only way to add an image to a page is to hard code it. Also, unfamiliar with “blueprint” in this context.
For example, I’ll have an About page that’s different than my other pages, and that page is just a body of text and an image. Is there a field I can create where I can determine that image (whether it be through a direct select or even a URL) and echo that to my PHP template?
Well, there are many ways to add images to a page. One way is directly in the template where you can just do something like:
$image = $page->images()->first();
or
$image = $page->images()->find('filename.jpg');
Or, in an image_field in your text file, you can use the kirbytext image tag
(image: filename.jpg)
and then render this in your template
<?php echo $page->image_field()->kirbytext() ?>
I guess you are not using the panel?
[Edit] but you were asking how to select images in admin panel. Well, to use the Kirby panel, you need to define so called “blueprints”, sort of templates for the forms that are displayed in the admin panel. In the blueprints, you define the fields and what sort of data those fields can accept, from simple text fields to radio buttons or select fields.
got me an image, but the problem here is it’s within the text field. I should clarify that that’s something I want to avoid. I want the image to be it’s own element that I can float right or left or whatever without it being dependent on the text field as a parent container.
I’m not 100% sure I’m doing the code right for the direct template injection (which at this point I’m fine with. Kirbytext looks wayyyy more complicated than I have time for).
This is my code but I’m getting a broken image link (am testing locally via MAMP so I’m not sure if that has something to do with it)…
There we go. I can HTML/CSS/jQuery like nobody’s business, but once you start getting into PHP territory I’m like “ehhhh”. This should help me on my way though. And I’ll review blueprints a bit more to see what I can accomplish with that.
Two things: if you use yaml() you cannot use the chaining syntax, but need to get an individual member by its key in square brackets (the yaml() method create an array).
$staffmember['staffimage']
Secondly, $staffimage is just a string, so you have to fetch the file first:
I also removed the superfluous img tags and added a missing endforeach etc. Pls. turn on debugging in your config file to get an error message if your code is not correct.
c::set('debug', true);
BTW, pls use three backticks before and after a code block to properly indent your code. I have corrected your example above, so you can go into edit mode to check out how that works.