How to add image type field to PDF template?

Hello everyone,

I am trying    <img src="{$product.product_image}"/>    in the PDF template HTML. But it fails.

How to add image type field to PDF template?

Thanks

Parents Reply Children
  • Sorry, I should have mentioned this before, the field will most likely contain only the id of the image  record, not the URL of where that image is stored, which is likely to be in your uploads directory.

    You will need to build the path to the image before you can use it as a src.

    You can start by looking at your Quoted Line Item, use the Inspect on the developer tools in your browser to see how the img tag is built. 

    Digging through the code for the image field type you can see that for the front end display the address for the file is built up in stages: 

    clients/base/fields/image/image.js

    you can see that the value is formatted:

        format: function(value) {
            if (value) {
                value = this.buildUrl() + "&_hash=" + value;
            }
            return value;
        },

    using an api to build the url

        buildUrl: function(options) {
            return app.api.buildFileURL({
                module: this._duplicateBeanModule ? this._duplicateBeanModule : this.module,
                id: this._duplicateBeanId ? this._duplicateBeanId : this.model.id,
                field: this.name
            }, options);
        },

    you can track down buildFileURL Api in the source code and see how they build the URL there...

    I often go down such rabbit-holes in search for answers  you'd be surprised how much you can learn just by diving deep and reverse engineering the code... 

    Francesca