1
votes

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?

1
You did register the bundle in Symfony right?DarkBee
Sure did, in AppKernel.php If I didn't I don't think it would even know where to look for the function qrcode_urlMicWit
Well there route is being defined in the QrController, did you clear your cache(s) after adding the bundle?DarkBee
Sure did, both dev and prod and tested both.MicWit
(The function qrcode_ur is a Twig_Function and can be found under QrCode/src/Twig/Extension/QrCodeExtension.php btw)DarkBee

1 Answers

2
votes

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