Reputation: 3498
I'm using the knp-snappy-bundle to generate PDF's out of twig.
But my css files are not loading.
I tried it with static url
, with absolute url
and with only asset url
, noting works, but these are the normal css files
which I also use when display for example in my edit form. Here are the three options I tried in my pdf.html.twig
file
// STATIC DOES NOT WORK
<link rel="stylesheet" href="https://localhost/test/boot.css">
// ASSET DOES NOT WORK
<link rel="stylesheet" href="{{ asset('test/boot.css') }}">
// ABSOLUTE DOES NOT WORK
<link rel="stylesheet" href="{{ absolute_url(asset('test/boot.css')) }}">
Always get this: Warning: Failed to load https://localhost/test/boot.css (ignore)
Upvotes: 0
Views: 3638
Reputation: 11
pdf.html.twig file do not extend with another file. Try this code, it works
<link href="{{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset('test/boot.css') }}" rel="stylesheet"/>
Upvotes: 1
Reputation: 99
As soon as we're in Symfony you could try in TWIG like the following
{% stylesheets
'test/boot.css'
filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
Your css file should be reside in your Symfony application web/test directory. Check availability in browser
http://localhost/test/boot.css
Should work
Upvotes: 0
Reputation: 7764
I presume you are using wkhtmltopdf
, in that case you need to use the absolute path to the css file. Not sure what the path is to your web folder, but something like this:
<link rel="stylesheet" href="/var/www/html/Symfony/test/boot.css">
I had this same problem with wkhtmltopdf
and had to hard code it like that.
Upvotes: 1