Hi,
Is there a way to define a method once, which will be available from all blueprints (site and pages) ?
Instead of declare this method in a Site plugin and in a custom page method?
Hi,
Is there a way to define a method once, which will be available from all blueprints (site and pages) ?
Instead of declare this method in a Site plugin and in a custom page method?
No, both Page and Site extend the ModelWithContent class, but you cannot define ModelWithContent methods in a plugin.
Could you provide an example what you want to achieve?
Why not create both a custom page and a custom site method in your plugin? In case they share a lot or all of the same code, you could outsource the logic to a function that is used in both methods, to reduce the amount of code.
I want to be able to display a button in the panel by calling a method in a info field.
The method just return a string which is html and css inline styles (display a button).
And the method has two parameters: $label (button text) and $url (the page called when you click the button).
And I would like to use this method both in a site and page blueprint whatever the template used.
Why not create both a custom page and a custom site method in your plugin?
Ho! we can do that?
You can define as many custom page
, user
,file
or site
methods in a single plugin, it’s just that you have to define custom site methods within the siteMethods
array and custom page methods within the pageMethods
array.
The site method and the page method can both have the same name (you only have to be careful that they don’t clash with methods defined in a PageModel, as these take precedence.
Custom page/site etc. methods defined via these extensions don’t become class member methods, they work, because the magic __call
method resolves them (just like fields in your content files are resolved via this magic method).