0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.