Append a blade @section inside a controller

Posted 4 years ago by james2doyle

I have been trying to figure out the best way to do this without using some hacky string-replace stuff. I want to be able to append content to a section in my view. But, I want to do this in my controller.

Here is some pseudo code for what I am looking to do:

return View::make('Page::create')
        ->section('styles', $stylesheet_tag) // something like this
        ->with('page', $page);

Is this possible? I haven't found any methods that would facilitate this kind of functionality.

More information: I am generating a view that has a dynamic form. I can append fields as I need them based on the settings for the form. This works great. But, once I start requiring additional javascript or CSS for these dynamic fields, I need to be able to properly append these to the @yield("styles") and @yield("scripts") sections in my layout.

Can I do this inside a controller or do I need to break out this additional fields into their own blade @include sections?

Please sign in or create an account to participate in this conversation.