Hi, i am normally pretty versed with php and html, normally working with wp / processwire/ drupal, now i want to set up a simple page with kirby.
I have bought the license, installed a page, and now pretty stuck.
I understand that the kirby is very powerful in itself,
and the preinstalled gallery version is exhausting, also the documentation seems fine,
but i can’t seem to find the simple stuff. Therefore my question, please, enlighten me:
1 - i need to define a template.php AND a blueprint.yml for ONE kind of pages (like projects) to be able to add new pages in the panel.
So like project.php and project.yml
Is this right?
2 - In these pages - I need a special image field (which will be repeated through these pages, lets say ONE image per page) - like “headerimage”
Where do i define this?
Do i have to make a new headerimage.yml blueprint and headerimg.php template for this?
i do not know if i am to use the image, or do i have to use the file method, where can i define this?
3 - text - How do i define multiple simple text fields for the panel and use it in the template.php for this kind of pages? Let’s say i want to have 3 column block with an icon and a text field in every column, which will be filled in every page of this kind.
If i have the 3 - i understand this will be a ?field? do i get to use it in other template too?
Perhaps my questions are stupid, but somehow i feel the documentation covers complicated issues, while abandoning the basics. For somebody green to this kind of work it is sadly maddening^
Thanks a lot for any help, as i really need it.
Best
I will try to answer you detailed questions later, but this recipe should give you a greater picture of how Kirby works, how blueprints, templates etc. play together.
Basically, a page type has a part for the form fields in the Panel (the blueprint), the text file that stores the content and the php template to display that content in the frontend.
I just can’t seem to wrap my head around the image stuff. It will probably be very easy and basic, and ill laugh about it later, but please help me understand here. So what if i would need to define 2 different images in my page template?
Let’s say i need a cover img (with a text field) and a headerimg.
I tried to define them both in my yml,
but i can’t call them.
The only way i get an image here is
WORKS, gets one image:
Let’s start with your cover field. This is a files field that can store one or multiple images. To get a single image (max: 1) from such a field:
if ( $image = $page->cover()->toFile() ) {
echo $image->url();
}
So with toFile() we convert the value that is stored in the content file into a file object and can then call all file methods on that object.
Similarly, we can use toFiles() instead of toFile() when multiple files are stored in such a field.
If you just call $page->image() this will get the first file that exists in the folder, but not what you store in your field.
Fetching files by template makes sense if they are not stored in a field but just uploaded via a files section. A files section doesn’t store the id of the file in your content.
It is important to understand this difference between fields and sections, since that is something that is confusing for people new to Kirby.
On a side note: for repeating stuff like your 3 textarea fields, it might make sense to use a structure field with a max of 3 items. This is particularly useful if you want to let the user select an icon for each if the fields.
hi! nope, there has to be a problem with me calling the template cover.yml
i am very thankful for your time. I hope i can understand this and proceed with the work
Page blueprint structure.yml
title: Structure
status:
draft: true
unlisted:
label: Hidden Page
text: The page is not listed in the main menu
listed:
label: Menu Page
text: The page is listed in the main menu
columns:
- width: 1/2
fields:
cover:
type: files
template: cover
uploads: cover
- width: 1/2
fields:
headimg:
type: files
template: headimg
max: 1
uploads: headimg
I can upload the img, but when editing the file (yes i have uploaded through panel), the template is not being read. Not even the default.
Oh now you’ve killed me!
This was it
Yeah, i was so used to the database functions that i totally forgot
I think i’ve got it now. You should add this little piece of information for the people with extra long cable such as myself
Thanks also for the other tips, ill be reading on it. I think i have now a greater understanding of how stuff works.
Any good reads on extending the (home)page with repeatable sections or other pages?
Also, how do i create nested menu’s?
Thank you very much, you showed me that kirby’s community is really worthwhile!
You can use that in a template if you want to check if there is a file that has the cover blueprint/template assigned. But note that you would not necessarily fetch the file that you selected via the files field.
Say, you have uploaded multiple files via your files field, but you only select one (because of max: 1). Still, there would be several of these files.
With your assignment, you would fetch the first image with that template that lives in the folder.