The project that I'm working on requires that I generate an EAN13 barcode for display on vouchers.

I'm attempting to implement the following as a Craft Plugin: https://github.com/rlt3/php-barcode

The part that I am unclear about is how exactly to define my Model to return an image to the calling template. Do I even need a Model ?

2 Answers 2


Bit of a late reply (But hope you can use this!), but I created a plugin to output barcodes within Craft templates via Twig:


I created it because one of our clients required a barcode to be output in to a generated PDF that got sent to their customers.


For reference, I highly recommend reading the Craft plugin docs: https://craftcms.com/docs/plugins

You can certainly use a Model, but it depends on how you want to architect the rest of your plugin. I like to think of a Model as a convenient way of transporting objects/data across the different layers of your plugin (Template Variables, Services, Controllers, etc.).

That plugin currently will just generate the image and output it directly to the browser, which may or may not be what you want from a template. What you may want to do is take that image and save it to the file system (in a temporary or permanent public place) and have your Twig template reference that file directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.