2

I am making a sales support system with Laravel 4. I have a form for recording projects and another for saving sales notes. There I want to enable users to add a new project without having to leave the create sales note form for the new project form. I have a partial for the create project form, which I use in both the normal way of creating a project and the one I use in the create sales note. In the latter case I need to display a cancel button in addition to the submit button, so I intended to pass a parameter to my form partial to tell wether the cancel button is needed or not, like so:

projects/create.blade.php:

@include("partials.NewProjectForm", array("cancel" => "no"))

salesnotes/create.blade.php:

@include("partials.NewProjectForm", array("cancel" => "yes"))

partials/NewProjectForm.blade.php:

@if($cancel == "yes")
  {{ Form::button("Cancel") }}
@endif

In the "no" case the partial receives the passed variable as expected, in the "yes" case however it throws the "Undefined variable: cancel" error. I have tried as well including the partial with View::make()->with(), with the same result. Whats going wrong there?

Thanks.

2 Answers 2

2

This answer ends up mentioning what you need. The trick is to use a different approach to rendering your partial.

Assuming you've got a partials directory under views that contains a file called header.blade.php add the following line the to view script you want to render the partial from:

{{ View::make('partials.blog.header', array('title' => 'test'))  }}

If you put the following line in header.blade.php you'll see that 'test' has been passed to your partial, and your partial has been rendered.

{{ $title }}

Hope that helps! (I was confused about this too when I first ran across it...)

Sign up to request clarification or add additional context in comments.

Comments

0

Your code is fine... That error could have been caused by a different call to the partial which had 'cancel' misspelled or missing. Perhaps the wrong 'salesnotes/create.blade.php' was deployed, or the 'salesnote' route directed to a different page which included the partial without setting the 'cancel' variable?

BTW - this doesn't solve your problem - but If you're creating a generic partial, suggest adding a check for isset($cancel) before checking for $cancel's value.

1 Comment

Thanks lost philosopher, thanks perNalin! I finally got to a completely different but successful approach forgetting about passing variables to partials: I am simply loading the forms depending on the context via ajax call into the corresponding divs and handling them with javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.