1

I want to display multiple charts in a single page or different pages. How can I reuse the blade file instead of repeating/retyping the code?

I created a plain blade file _chart-widget.blade.php and I want the variable value to change depending on the page, or depending on what I want to set the variable in each <section> of a page

<!--begin::Charts Widget 1-->
<div class="card {{ $class ?? '' }}">
    <!--begin::Header-->
    <div class="card-header border-0 pt-5">
        <!--begin::Title-->
        <h3 class="card-title align-items-start flex-column">
            <span class="card-label fw-bolder fs-3 mb-1">Recent Statistics</span>

            <span class="text-muted fw-bold fs-7">More than 400 new members</span>
        </h3>
        <!--end::Title-->

        <!--begin::Toolbar-->
        <div class="card-toolbar">
            <!--begin::Menu-->
            <button type="button" class="btn btn-sm btn-icon btn-color-primary btn-active-light-primary" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">
                {!! theme()->getSvgIcon("icons/duotune/general/gen024.svg", "svg-icon-2") !!}
            </button>
            {{ theme()->getView('partials/menus/_menu-1') }}
            <!--end::Menu-->
        </div>
        <!--end::Toolbar-->
    </div>
    <!--end::Header-->

    <!--begin::Body-->
    <div class="card-body">
        <!--begin::Chart-->
        <div id="kt_charts_widget_1_chart" style="height: 350px"></div>
        <!--end::Chart-->
    </div>
    <!--end::Body-->
</div>
<!--end::Charts Widget 1-->

How can I make the code above dynamic and reusable when I @include it?

Abdulrahman Mushref
  • 1,012
  • 2
  • 18
  • 40

2 Answers2

2

You can include views in Laravel blade template.

here you can read more.

Just use like this:

<div>
    @include('_chart-widget')
</div>

If you need to pass data to your widget component, just give parameters as an array to your component:

@include('view.name', ['status' => 'complete'])
gguney
  • 2,512
  • 1
  • 12
  • 26
1

If you want variables to be different in each page simply pass vairables from Controller.If you are on the same page and including same blade multiple times this can help you:

@include('view.name', ['code' => 'complete'])

This will set different values for $code variable in different sections.

Check out documentation here.

Dharman
  • 30,962
  • 25
  • 85
  • 135