Reputation: 685
So I want to make a QR code dynamically by feeding it a URL in my TWIG template in Symfony. I have the endroid/QrCode bundle installed and seems to be fine, but I'm not sure how to get TWIG to create a QR code image!
So from the GitHub page, all it says for TWIG is:
Twig extension
The bundle provides a Twig extension for generating a QR code URL, path or data URI. You can use the second argument of any of these functions to override any defaults defined by the bundle or set via your configuration.
<img src="{{ qrcode_path(message) }}" />
<img src="{{ qrcode_url(message, { writer: 'eps' }) }}" />
<img src="{{ qrcode_data_uri(message, { writer: 'svg', size: 150 }) }}" />
So I figured for a test, the easiest thing to do would be something like:
<img src="{{ qrcode_url('http://www.test.com') }}" />
However, this brings up the error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "endroid_qrcode_generate" as such route does not exist.").
Anyone got the TWIG extension for this working?
Upvotes: 1
Views: 5615
Reputation: 2745
make sure you include the route configuration for the bundle, as it is stated in the documentation
Add the following section to your routing to be able to handle QR code URLs. This step can be skipped if you only use data URIs to display your images.
add the routing config to e.g. app/config/routing.yml
:
EndroidQrCodeBundle:
resource: "@EndroidQrCodeBundle/Controller/"
type: annotation
prefix: /qrcode
Upvotes: 2