Skip to content

@pushonce doesn't seem to work as Laravel's blade. #192

@n1njatalon

Description

@n1njatalon

When using @pushonce for some styles in a component, it seems that it is duplicating the styles. Looking at the docs and code it seems that the @pushonce will only work if used in the same file multiple times. However Laravel's blade uses it per component used as specified in their docs:

The @once directive allows you to define a portion of the template that will only be evaluated once per rendering cycle. This may be useful for pushing a given piece of JavaScript into the page's header using stacks. For example, if you are rendering a given component within a loop, you may wish to only push the JavaScript to the header the first time the component is rendered.

Here is copy of my component:

<div class="{{$additionalclasses ?? ""}}">
    @if($slot)
        <div class="d-flex column-gap-4">
            <p class="flex-grow-2 fw-bold mt-1">{!! $slot !!}</p>
        </div>
    @endif
    <div class="btn-group {{$slot ? "me-5" : ""}}" role="group">
        <input type="radio" class="btn-check" name="{{$name}}"
               id="{{$name}}Yes" autocomplete="off" value="1">
        <label class="btn btn-primary border rounded-start fw-bold" for="{{$name}}Yes">Yes</label>

        <input type="radio" class="btn-check" name="{{$name}}"
               id="{{$name}}No" autocomplete="off" value="0">
        <label class="btn btn-primary border rounded-end fw-bold" for="{{$name}}No">No</label>
    </div>
</div>

@pushonce('styles')
    <style>
        .btn-group>label {
            min-width: 50px;
        }
    </style>
@endpushonce

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions