1

I have a view that creates 9 blocks in an HTML page. Each block can either have one large note (like a sticky note) or up to 6 small notes.

On each of the notes there is an option to show a comment.

The code to make those comment options thus appears 18 times in the view - there must be a better way to do it rather than have the code block appear so many times. A function that writes it out perhaps?

This is the code block:

<!-- start comments popover  -->                                            
<div class="popover-medium">
    <a href="javascript:void(0)" class="icon-entypo icon-text-document btn-note trigger" data-toggle="popover" data-placement=right></a>
    <div class="popover-avatar content hide">
        <ul class="row popover-content border-bottom list-inline">
            <li class="col-xs-9">
                <span class="small clearfix"></span>
                <span class="small">
                    @if (!empty($name->comments))
                        {{$name->comments}}
                    @else
                        No comments
                    @endif
                </span>
            </li>
        </ul>
    </div>
</div>
<!-- end comments popover  -->      

Any ideas/direction would be greatly appreciated!

GWed
  • 15,167
  • 5
  • 62
  • 99
Mhluzi Bhaka
  • 1,364
  • 3
  • 19
  • 42

1 Answers1

3

Add your code block to a new blade file e.g. myblock.blade.php

Then in your main view you can call @include('myblock')

When the page renders it will replace the @include line with your block of code.

Also, its not totally clear what your question is. But it may also be worth noting that you can do this:

@foreach($array as $item)
@include('myblock', ['item'=>$item])
@endforeach

Then just reference $item in your block of code. You may actually not need to pass the $item as an argument to @include as I think when the page renders, the script can use all variables in the page.

Note: Some people struggle with the naming convention of blade views. See my answer to a previous post if you are struggling

Community
  • 1
  • 1
GWed
  • 15,167
  • 5
  • 62
  • 99