Use a default for all templates in c::get()?

Hi,
I want to use a selfwritten plugin only on definied pages but only if the config is set it.
Is it possible to use the default config value in c::get() for all pages? If yes, what have I to write in?

This is what I use in my plugin if($file->page() == c::get('uploadresize.page', '')){…

Cheers

I don’t quite understand what you want to define in the options, a single page UID? Multiple pages?

HI,
so late online? :slight_smile:

I want that the user can define a single page or multipage. If no one is define it should work on all pages. And i don’t know what I have to write in my c::get() as default for all pages if nothing is declared.

Here I find also a situation where it could be difficult If I want to have all childrens of a page.

Well, one thing you could do is pass an array of page UIDs, and then check if the given page UID is in that array. But of course you don’t want to pass an array of hundreds of subpages, I don’t know how you want to handle that.

c::set('uploadresize.page', ['page-a', 'page-b', 'page-c']);

For the case where it should apply to all pages, you’d have to check if the option is set or not. A default then doesn’t make sense.

1 Like

Hi,
thank you. This works so long if I don’t have childpages.

$filePage = $file->page();
if(!c::get('uploadresize.page') OR in_array($filePage, c::get('uploadresize.page')) OR in_array($filePage->parent(), c::get('uploadresize.page'))){… 

It looks that $file->page()->parent() doesn`t exist. Is there a way to get the parent or grandparent page of $file?

It should work. What do you get if you

dump($filePage->parent());

In any case, I would rather use the UIDs here, anyway, instead of relying on Kirby to return the UID of the page in a string context.

Hey,
if i use the $filePage->parent() in my if-clause
if(!c::get('uploadresize.page') OR in_array($filePage, c::get('uploadresize.page') OR in_array($filePage->parent(), c::get('uploadresize.page'))){… I get an HTTP-Error 500 in the panel.

And if I use dump() I get no output. This was the reason for my question about debugging in my forumthread before.

Best