Tet using the variable instead of a string in the include statement.
@include('mergefields', ['insertFldId'=>$subject,'mergeFldId'=>$mergefields,'mergefields' => $mergefields ])
I have a blade file, that accepts some variables and builds a dropdown list of action items. The action is an onClick that takes the current menu item, and inserts it into a target field. This will be reused several times in the parent blade file. On each @include, I specify a different target field. The problem I'm running into, is that the included blade file, is exactly the same, as if it isn't be reparsed with new data, each time it is included. This might be "as designed" but that would seem to defeat the purpose of reusable blade components. Thus, I must be doing something wrong. Code snippets below, I can provide more if necessary.
<div class="form-group">
{{ Form::label('description', 'Description:') }}
{{ Form::text('description', null, ['class' => 'form-control']) }}
@include('mergefields', ['insertFldId'=>"description",'mergeFldId'=>"mergefields",'mergefields' => 'mergefields', ])
</div>
<!-- Form Input -->
<div class="form-group">
{{ Form::label('subject', 'Email Subject:') }}
{{ Form::text('subject', null, ['class' => 'form-control']) }}
@include('mergefields', ['insertFldId'=>"subject",'mergeFldId'=>"mergefields",'mergefields' => 'mergefields', ])
</div>
Here is the relevant part of mergefields.php
@foreach($mergeflds as $type => $fields)
<div class="btn-group" role="group">
<button id="btnGroupVerticalDrop1" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {{ $type }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop1">
@foreach($fields as $label => $mergefld)
<li>
<a href="#" onClick='updateMergeField("{{$insertFldId}}","{{$mergeFldId}}","{{$mergefld}}")'>{{$label}}</a>
</li>
@endforeach
</ul>
</div>
@endforeach
You can see that "insertFldId" is different for each rendering of the mergefields.blade.php file. But looking at the resultant html, and function, it is using "description" in both instances. What am I doing wrong?
Solved - and an apology.
I was on a wild goose chase, and blade really was rendering each instance of the include with different data. The problem was that in the include, the button definition to pop up the menu (a modal div) was the same for both instances. So when I press the button under the "description" field, it called "mymodal". When I clicked the button under the "subject" field, it called mymodal again. When troubleshooting my code, I did "not" view-source like I should have, or I would have saved many hours. I simply "inspected" the element in the modal box, and saw that it was wrong. When I viewed the entire page source, I see two instances of the "mymodal" content, with different variable substitutions but the same div name. My browser just rendered the first one it saw. The fix was very simple, the lesson learned was expensive.
<button class="btn btn-default btn-xs" type="button" data-toggle="modal" data-target="#myModal-{{$insertFldId}}">Merge Fields</button
<div id="myModal-{{$insertFldId}}" class="modal fade" role="dialog">
Please or to participate in this conversation.