pst
August 22, 2019, 9:57am
1
Hi, I`m trying to show a blueprint section based on the intended page template.
I tried with an additional info field where I display the template-name:
# fields/intended_template.yml
intended_template:
label: Intended Template
type: info
text: "{{ page.intendedTemplate }}" #team_member
# sections/contact_details.yml
type: fields
headline: Contact Details
when:
intended_template: team_member
but this does not work.
Is there another way to evaluate the sections conditional?
Something like:
when:
"{{ page.intendedTemplate == 'team_member'}}"
or can I create a custom page method which returns a boolean:
when:
"{{ page.isIntendedTemplate('team_meber')}}"
Can someone point me in the right direction to solve this?
Cheers
Peter
You can only work with conditions from another field’s value. Since the info field doesn’t store anything in the content file, I think this doesn’t work.
pst
August 22, 2019, 10:05am
3
So I need to build a custom (hidden) field which stores the intended template?
Yes, a hidden field, but you don’t have to build it, you can create a hidden field in your blueprint and then update this field with a hook on page creation.
pst
August 22, 2019, 10:44am
5
@pixelijn : Thanks!
This will change the intended_template field according to my needs:
#site/config/config.php
return [
'hooks' => [
'page.create:after' => function ($page) {
$page->update(['intended_template' => $page->intendedTemplate()]);
},
'page.changeTemplate:after' => function ($newPage, $oldPage) {
$newPage->update(['intended_template' => $newPage->intendedTemplate()]);
}
],
...