Ad

Blade Component Variables Not Rendered

- 1 answer

I have used the Laravel @component statements successfully before in my project, but for some reason my variables aren't being rendered in the following case.

<div id="{{ $modalId }}" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
            <h4 class="modal-title" id="modal-title">Add a user</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
      <div class="modal-body">
      </div>
    </div>
  </div>
</div>
@component('components.modal_bootstrap')
  @slot('modalId')
    {{ 'test' }}
  @endslot
@endcomponent

Expected Result

test is rendered as the id of the modal dialog.

Actual Result

{{ $modalId }} is the id of the modal dialog.


I have also tried and copy pasted the examples shown in the documentation: https://laravel.com/docs/6.x/blade, but the same problem persists. I think I'm missing something obvious, but I can't figure out what it is.

Ad

Answer

If the curly braces are being rendered out as-is it's usually a sign that the file extension is incorrect, make sure you file ends in .blade.php or it won't be parsed as a blade template

Ad
source: stackoverflow.com
Ad