I want to @include a view in my main view. The thing is I've wrote sοme javascript code to interact with that piece of code. Is there a way to include both html and javascript code, since for the second one I have to add <script> tag? I @include this view in many files so I don't want to hardcoded.
Add a comment
|
1 Answer
Here's three options of things you can do, but there are plenty more:
<html><body>
<!-- A javascript to be added by a particular view-->
<script type="text/javascript">
@yield('in-view-javascript')
</script>
<!-- A javascript only files, no script tag-->
<script type="text/javascript">
@include('views._partials.javascript-1')
@include('views._partials.javascript-2')
@include('views._partials.javascript-3')
</script>
<!-- A javascript code with script tag-->
@include('views._partials.javascript-code')
</body></html>
In views you can
@section('in-view-javascript')
console.log('in-view-javascript');
@stop
Or you can include another javascript file here:
@section('in-view-javascript')
@include('views._partials.javascript')
@stop
Your javascript-1, javascript-2, javascript-3 would be just javascript without the <script> tag.
And javascript-code would be a full javascript code, including the tag.