I have written a custom kirbytag that needs to access a variable that is set up in a controller. However, when I try to use this variable in my kirbytag snippet plugin, it lets me know
Undefined variable: foo
How can I use such a variable in the kirbytag snippet plugin?
Yes, exactly. I have a controller home.php and would like certain kirbytags that appear on text blocks of my home page to work with data from this controller at the time of their parsing.
Also, if I could easily access the page object from the kirbytag, is there not maybe an easier way to store the data that I need within the page object somehow and then access it from the kirbytag like that? I mean, I don’t have to use a controller, if there are easier ways.
I have a page with a blocks field. Before I do any rendering to the page, I need to loop over all the blocks to retrieve certain information about it and collect it into an array. I do this in the controller (as it is the most appropriate place to do so).
Then, I start rendering all those blocks, including some blocks that include my kirbytag that accesses information from the array that I collected before.
I got it to work now with the kirby()->controller('home', ['page' => $tag->parent()]); way, you suggested above. However, if there is an easier (and maybe also cheaper) way to get the same thing done, I would be interested.
What do you mean? What I need them for specifically?
Those are Kirbytags that link you to an image within the text (something like Fig. 1: A Mountain). And I need the controller variable to first run over all the images within my block to actually figure out the number for each image. Once I have done this in the controller, I can then target these images via a slug field I set up for each of them. So I use my kirbytag like this
(fig: a-mountain)
And it then gets the correct number automatically. As I said, very open for suggestions to solve this somehow more easily.