简体   繁体   中英

Blade templating (Laravel) overwrite issues

I have a "master" layout that has a section: @yield('other-scripts')

I use this master template in another view ( especie.blade.php ):

@extends('layouts.master')

@include('layouts.editarEspecie')

@section('other-scripts')
    {{ HTML::script('js/lightbox.js') }}
@stop

Inside layouts.editarEspecie , @section('other-scripts') is also overwritten:

@section('other-scripts')
    {{ HTML::script('js/chosen.jquery.js') }}
    {{ HTML::script('js/chosenScriptModal.js') }}
    {{ HTML::script('js/scripts.js') }}
@stop

The problem is that @include('layouts.editarEspecie') goes first, so @section('other-scripts') never adds the part inside especie.blade.php .

What can I do so that both part are added and it ends like this?

{{ HTML::script('js/chosen.jquery.js') }}
{{ HTML::script('js/chosenScriptModal.js') }}
{{ HTML::script('js/scripts.js') }}
{{ HTML::script('js/lightbox.js') }}

PS: I do this because lightbox.js is always necessary, but chosen.jquery.js, chosenScriptModal.js, scripts.js may not always be needed.

Inside layouts.editarEspecie dont have a "section" - just have this:

{{ HTML::script('js/chosen.jquery.js') }}
{{ HTML::script('js/chosenScriptModal.js') }}
{{ HTML::script('js/scripts.js') }}

Then those 3 lines will always be included.

The thing is, I don´t want those 3 lines to always go inside layouts.editarEspecie, just when certain conditions are met (not shown here)

ummmmm.. i know its like the fastest thing ever but you can always PHP if it

<?php
if (condition)
 {
 ?>
{{ script here}}
<?php
}
else
{}
?>

Sorry for lazy explanation but i am sure you get the hint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM