1

I'm twig beginner, I Want to get the CSS file content and not the path to be clear, this file is located in:-

Bundle/Ressources/public/css/'~var~'/main.css 

var is a dynamic variable, so I used the source function of twig, but it seems that I don't point to the right path. Here is my code:

 <style>
 {{ source('/Bundle/Resources/public/css/'~var~'/main.css',  ignore_missing = true)  }} 
</style> 

Any help please.

1 Answer 1

0

You are right. You are not using correct notation for the path.

In your case, if your bundle is named FooBundle, you should use:

{{ source('@FooBundle/Resources/public/css/'~var~'/main.css',  ignore_missing = true)  }} 

If your file's location was inside Resources/views/ for example Resources/views/foo/bar.html.twig you could use even shorter variants:

{{ source('FooBundle:foo:bar.html.twig',  ignore_missing = true)  }} 

or:

{{ source('@Foo/yourTemplate.html.twig',  ignore_missing = true)  }}

See also: http://symfony.com/doc/current/templating/namespaced_paths.html

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.