Hi there,
I’m exploring the blueprint with categories and trying to create a function where it changes the layout depending on which category box is ticked/active.
is there anything equal to the intendedTemplate but for categories?
was toying with this kind of structure:
<?php if($page->intendedCategory() == 'visible'): ?>
//do something
<?php endif ?>
Grateful for any help!
xx
Yes, just like that, if that’s what your field is called.
Hi!
I can’t seem to find the intendedCategory() in the cheatsheet, is it a valid function?
Xx
No, as I said, I expected this to be a field in your content file. What exactly are you trying to find here?
oh! what is the best way to check if the content file has the field ‘visible’ or not?
So you are not using the inbuilt visibility functions, but you really have a field for that? What type of a field is that?
Maybe you want to check out all Kirby’s wonderful field methods: https://getkirby.com/docs/cheatsheet#field-methods
Especially:
very helpful!
is there any way to have it work with multiple category options?
right now using the exist() or isNotEmpty() function, it seems to target all at once.
The structure i’m toying with looks like this:
categories:
label: Categories
type: Checkboxes
options:
none: None
left: Left
right: Right
<?php if($page->categories()->isNotEmpty()): ?>
<img style="float:<?php echo $page->right() ?>" src="/image.jpg">
<?php endif ?>
kind of want something like this:
<?php if($page->categories('right')->isNotEmpty()): ?>
<img style="float:<?php echo $page->right() ?>" src="/image.jpg">
<?php endif ?>
thankful for advice,
xx
Are you sure that checkboxes are the right choice? It does not seem to make sense to check more than one option? I’d use a radio field. Then you could do this:
<img style="float:<?php echo $page->categories() ?>" src="/image.jpg">
with none
being the default:
default: none;
The thing to check here would be rather if the image exists, if you are not hardcoding the image.