1

I am trying to call css and js from

Project/src/Front/bundle/AdminBundle/Resources/Public/css

OR js file

Project/src/Front/bundle/AdminBundle/Resources/Public/js

how can i include them in a proper way?

1
  • JS & CSS need to be called from your view, not your controller.( search for {{ asset() }} twig methods. Or provide an example where you need to call them from your controller and not from your view Commented Dec 6, 2016 at 14:03

2 Answers 2

1

I would suggest adding to your twig blocks, this is typical usage, like so:

{% block stylesheets %}
    <link rel="stylesheet" href="/css/main.css" />
{% endblock %}
...
{% block javascripts %}
    <script src="{{ asset('script/myJavascript.js') }}"></script>
{% endblock %}

The above shows paths under the web folder, which is a good idea instead of your src folder. So css above is web/css/main.css and js path is web/script/myJavascript.js. That's a good way to do it. i show using asset() and without. You can try both to see what works best.

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

1 Comment

Thanks...this is also one of the solution
1

One of the solution I have found is....

make a hard copy of the assets in web/ directory with single command..

php bin/console assets:install

now , check your web directory where all custom css/js folder are mirrored in "bundles"

How to include??

<link rel="stylesheet" href="{{ asset('bundles/bundlename/css/botstrap.css') }}"/>

So,It worked for me!!

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.