Question

I have a partial view that I am using to provide a pair of form select fields, and both sets of options depend on some variables set by a view composer for this view.

I would like to implement this view as a Form::macro instead so that I can parameterize some parts of it. However, I'm not sure how I can point the view composer at a macro instead of a partial view. Is this even possible?

I could go the route of pointing the composer at any view that I'm using the macro in, but I'd much rather have the option data load automatically any time I use the macro as it is a common component in my web app.

Was it helpful?

Solution

I use partials for some Bootstrap UI components, and create a macro to connect data into the template, so I only use HTML::macro or Form::macro to access them:

Form::macro('myMacro', function($data) { return View::make('myPartial', $data); };

OTHER TIPS

This doesn't really answer the primary question, but one way I can get what I want is to use View::Make instead of @include in my views.

Where I was using:

@include('thepartial')

I can use something like this instead:

{{ View::make('thepartial')->with(array('param1'=>$param1, 'param2'=>$param2, ...) }}

This way I get the parameterization I want, and I still get the composer's effects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top