Getting Controller variable from View file
Permalink
Quick question and hopefully an easy one...
I am creating a custom block template for the 'calendar event' block. I want to have the event category color displayed.
$bkcolor = $linkFormatter->getEventOccurrenceBackgroundColor($occurrence);
The core controller for this block seems to have the values already but they are not passed to the view file. I was able to make it work by modifying the core controller but I know that is a no-no. Here's how I modified it...
My question is... is there any way to grab the linkFormatter from the view file without having to modifying the core with $this->set('linkFormatter', $linkFormatter); ?
Thanks in advance,
C
I am creating a custom block template for the 'calendar event' block. I want to have the event category color displayed.
$bkcolor = $linkFormatter->getEventOccurrenceBackgroundColor($occurrence);
The core controller for this block seems to have the values already but they are not passed to the view file. I was able to make it work by modifying the core controller but I know that is a no-no. Here's how I modified it...
public function view() { $this->set('event', $this->getEvent()); $displayEventAttributes = array(); if (isset($this->displayEventAttributes)) { $displayEventAttributes = json_decode($this->displayEventAttributes); } $this->set('displayEventAttributes', $displayEventAttributes); $occurrence = $this->getOccurrence(); $this->set('occurrence', $occurrence); $provider = $this->app->make(CalendarServiceProvider::class); if ($occurrence) { $this->set('event', $occurrence->getEvent()); $linkFormatter = $provider->getLinkFormatter(); $this->set('linkFormatter', $linkFormatter);// <-- This allows it to work properly but requires modifying the core controller
Viewing 15 lines of 21 lines. View entire code block.
My question is... is there any way to grab the linkFormatter from the view file without having to modifying the core with $this->set('linkFormatter', $linkFormatter); ?
Thanks in advance,
C
There is nothing there that relies on anything from the controller, it's just generic code that would work anywhere. So you can use it directly in your view.
So in your view, all you need to do is
And that's it you're good to go without overriding the controller