Hi there,
i was wondering wether it woulb be possible to have 2 seperate instances of modules on one page.
e.g. i have a 2 column site layout and want people to be able to customize subpages putting the available modules in the order they want and decide wether to have them in the left or right column of a page. In the backend i would mimic this 2 column setup and have a modules section to the left and right with all modules available on both sides.
so far it seems while you can display two instances of modules they mimic each other and can’t be edited seperately.
that would be my current blueprint setup:
title: Inserat
columns:
left:
width: 1/2
sections:
fields:
fields:
title:
label: Projekttitel
type: text
required: true
info3:
label:
type: info
text: Titelbild taucht im Karussel auf der Startseite auf
author:
label: Künstler/in
type: text
required: true
hero_image:
label: Karussel Titelbild
type: files
limit: 1
required: true
anzeige:
label: "ebay Kleinanzeigen Inserat URL"
type: url
required: true
line:
type: line
info1:
label:
type: info
text: Kurzbeschreibung & Projekttext (optional zweisprachig)
lang_de_short:
label: Kurzbeschreibung Deutsch
type: toggle
shorttext_de:
when:
lang_de_short: true
label: kurzer Text
type: textarea
lang_en_short:
label: short description english
type: toggle
shorttext_en:
when:
lang_en_short: true
label: short text
type: textarea
lang_de_long:
label: Projekttext Deutsch
type: toggle
description_de:
when:
lang_de_long: true
label: langer Text
type: textarea
lang_en_long:
label: textfield english
type: toggle
description_en:
when:
lang_en_long: true
label: description
type: textarea
line2:
type: line
info2:
label:
type: info
text:
1. Status Schalter auf Live stellen sobald Kleinanzeige live geht
2. Kategorie angeben unter der bei Kleinanzeigen inseriert wird
live_toggle:
label: Status
type: toggle
text: Live
tags:
label: Kategorien
type: tags
accept: options
separator: "|"
max: 1
options:
- "Auto, Rad & Boot"
- "Dienstleistungen"
- "Eintrittskarten & Tickets"
- "Elektronik"
- "Familie, Kind & Baby"
- "Freizeit, Hobby & Nachbarschaft"
- "Haus & Garten"
- "Haustiere"
- "Immobilien"
- "Jobs"
- "Mode & Beauty"
- "Musik, Filme & Bücher"
- "Nachbarschaftshilfe"
- "Unterricht & Kurse"
- "Verschenken & Tauschen"
required: true
line3:
type: line
info4:
label:
type: info
text: weitere optionale Elemente für die linke Spalte der Projektseite
modules:
type: modules
right:
width: 1/2
sections:
modules2:
type: modules
results in this:
@antonlinus Looks like we are in the wrong context here, this thread is about a Kirby 2 plugin? You are probably talking about @thguenther’s plugin.
The modules section is just a regular pages section with the parent set to the modules container /modules
.
You can create two separate modules containers and overwrite the parent
:
modules:
type: modules
parent: page.find("sidebar")
Just make sure this container page exists. Have a look at the Subpage builder recipe — I’m using a route:after
hook.
jup sorry thought this was it
Maybe the README helps you understand how the plugin works.
It’s also always a good idea to have a look at the content files/folders. A great advantage of file-based CMS.
hm i’m sorry but it seems this exceeds my capabilities. i looked at your linked articles and adapted my blueprint accordingly. i also took your advice and looked at the content folders and i understand that whenever a module is added to a page it creates a subpage folder called modules in the page folder.
The way i understand your solution is to have kirby create seperate subfolders for the modules section in the left and the right column e.g. modules_right & modules_left.
I don’t get how i would achieve that thou. I added the parent overwrite in my blueprint but that alone didn’t do the trick it seems. I don’t get how to edit your hooks if that is what i would need to do.
Could you explain your solution in more detail?
again thanks!
Blueprint Setup:
title: Inserat
columns:
left:
width: 1/2
sections:
content_links:
type: fields
fields:
title:
label: Projekttitel
type: text
required: true
titel:
label: Linke Spalte
type: headline
numbered: false
author:
label: Künstler/in
type: text
required: true
info1:
label:
type: info
text: Titelbild taucht im Karussel auf der Startseite auf
hero_image:
label: Karussel Titelbild
type: files
limit: 1
required: true
tags:
label: Kategorien
type: tags
accept: options
separator: "|"
max: 1
options:
- "Auto, Rad & Boot"
- "Dienstleistungen"
- "Eintrittskarten & Tickets"
- "Elektronik"
- "Familie, Kind & Baby"
- "Freizeit, Hobby & Nachbarschaft"
- "Haus & Garten"
- "Haustiere"
- "Immobilien"
- "Jobs"
- "Mode & Beauty"
- "Musik, Filme & Bücher"
- "Nachbarschaftshilfe"
- "Unterricht & Kurse"
- "Verschenken & Tauschen"
required: true
line1:
type: line
info2:
label:
type: info
text: Kurzbeschreibung & Projekttext (optional zweisprachig)
lang_de_short:
label: Kurzbeschreibung Deutsch
type: toggle
shorttext_de:
when:
lang_de_short: true
label:
type: textarea
lang_en_short:
label: short description english
type: toggle
shorttext_en:
when:
lang_en_short: true
label:
type: textarea
lang_de_long:
label: Projekttext Deutsch
type: toggle
description_de:
when:
lang_de_long: true
label:
type: textarea
lang_en_long:
label: project textfield english
type: toggle
description_en:
when:
lang_en_long: true
label:
type: textarea
line2:
type: line
info3:
label:
type: info
text:
1. Status Schalter auf Live stellen sobald Kleinanzeige live geht
2. Kategorie angeben unter der bei Kleinanzeigen inseriert wird
modules:
type: modules
parent: page.find("module_links")
right:
width: 1/2
sticky: true
sections:
content_rechts:
type: fields
fields:
titel2:
label: Rechte Spalte
type: headline
numbered: false
info4:
label:
type: info
text: Link zum Kleinanzeigen Inserat - Status auf live setzen solange die Anzeige live ist
anzeige:
label: "ebay Kleinanzeigen Inserat"
type: url
live_toggle:
label: Status
type: toggle
text: Live
line3:
type: line
info5:
label:
type: info
text: Elemente in der rechten Spalte der Projektseite können individuell ausgewählt & sortiert werden
modules:
type: modules
parent: page.find("module_rechts")
That’s not correct. We need the modules container before modules can be added. It’s can be added automatically via the route:after hook.
Your blueprint looks alright. The folder structure has to look like this then:
📄 Page
📄 Subpage A
📄 Subpage B
🗂 module_links
📄 Module A
📄 Module B
🗂 module_rechts
📄 Module C
📄 Module D
To be honest I’m not sure if my modules plugin is the right fit for your use case. Maybe have a look at the builder field?
The problem is that both module sections in the blueprint above use the same key, i.e. modules. In the first blueprint, they had different keys, modules and modules2, now not anymore.
2 Likes
This is how you do this in your plugin correct?
Or can it be more simple as in whenever a subpage is created also create two folders (e.g. modules_left & modules_right?
'route:after' => function ($route, $path, $method) {
$uid = explode('/', $path);
$uid = end($uid);
$uid = str_replace('+', '/', $uid);
$page = kirby()->page($uid);
if ($page) {
if(!$page->find('modules') AND $page->intendedTemplate() != 'modules') {
$modules = false;
foreach($page->blueprint()->sections() as $section) {
if($section->type() == 'modules') $modules = true;
}
if($modules) {
try {
$modulesPage = $page->createChild([
'content' => ['title' => 'Modules'],
'slug' => 'modules',
'template' => 'modules'
]);
}
catch (Exception $error) {
throw new Exception($error);
}
if($modulesPage) {
$modulesPage->publish();
}
}
}
}
},
You’re using an old version of the plugin. I changed the route with version 0.6.1.
But yeah, this is the code responsible for the creation of the modules container. You can find some simpler methods in the subpage builder recipe.
and if i have my blueprint setup like in my other post (exept with different names for the modules instances) it will ignore your hook and instead create the subpages in the dedicated left & right folders?
It will not ignore my hook, but that shouldn’t be an issue.
I’d probably use the existing modules
folder for the left modules and a modules_right
folder. The empty modules
folder won’t do anything, though.
The parent:
setting on the pages sections defines where the modules will be added.
i don’t know what i am doing wrong but i just can’t get it to work
I manually generated a “modules_right” folder in /content/mysubpage/anothersubpage/
thats where the modules folder was auto-generated as well.
i adapted my blueprint like this:
title: Inserat
columns:
left:
width: 1/2
sections:
content_links:
type: fields
fields:
info1:
label:
type: info
text: Titelbild taucht im Karussel auf der Startseite auf
hero_image:
label: Karussel Titelbild
type: files
limit: 1
required: true
titel:
label: Linke Spalte
type: headline
numbered: false
title:
label: Projekttitel
type: text
required: true
author:
label: Künstler/in
type: text
required: true
info3:
label:
type: info
text:
Kategorie angeben unter der bei Kleinanzeigen inseriert wird
tags:
label: Kategorien
type: tags
accept: options
separator: "|"
max: 1
options:
- "Auto, Rad & Boot"
- "Dienstleistungen"
- "Eintrittskarten & Tickets"
- "Elektronik"
- "Familie, Kind & Baby"
- "Freizeit, Hobby & Nachbarschaft"
- "Haus & Garten"
- "Haustiere"
- "Immobilien"
- "Jobs"
- "Mode & Beauty"
- "Musik, Filme & Bücher"
- "Nachbarschaftshilfe"
- "Unterricht & Kurse"
- "Verschenken & Tauschen"
required: true
line1:
type: line
info2:
label:
type: info
text: Kurzbeschreibung & Projekttext (optional zweisprachig)
lang_de_short:
label: Kurzbeschreibung Deutsch
type: toggle
shorttext_de:
when:
lang_de_short: true
label:
type: textarea
lang_en_short:
label: short description english
type: toggle
shorttext_en:
when:
lang_en_short: true
label:
type: textarea
lang_de_long:
label: Projekttext Deutsch
type: toggle
description_de:
when:
lang_de_long: true
label:
type: textarea
lang_en_long:
label: project textfield english
type: toggle
description_en:
when:
lang_en_long: true
label:
type: textarea
modules:
type: modules
right:
width: 1/2
sticky: true
sections:
content_rechts:
type: fields
fields:
titel2:
label: Rechte Spalte
type: headline
numbered: false
info4:
label:
type: info
text: Link zum Kleinanzeigen Inserat
anzeige:
label: "ebay Kleinanzeigen Inserat"
type: url
info6:
label:
type: info
text: Status auf live setzen solange die Anzeige live ist
live_toggle:
label: Status
type: toggle
text: Live
line3:
type: line
info5:
label:
type: info
text: Elemente in der rechten Spalte der Projektseite können individuell ausgewählt & sortiert werden
Module-rechts:
type: modules
parent: page.find("modules_right")
and it loads in my panel like this:
yet whenever i add a module in any of the to instances it will put the module in /content/…/…/modules and it will show up in both instances.
What am i doing wrong?
I see. Could you please try this fix I just released?
1 Like