Ignore missing assets



  • Hi,

    is there a possibility to ignore a missing asset?
    I would like to load the asset "/logo.png" but if it doesn't exist, I want to take another logo.
    I was trying to do this in JavaScript (check if the result of {#asset... is not empty etc.) but get an error that the asset "/logo.png" was not found.

    Regards
    Jens



  • Hi, there is no option to ignore missing at this moment.
    However, you have a lot of power with a custom script to achieve what you need
    https://jsreport.net/learn/scripts

    const jsreport = require('jsreport-proxy')
    async function beforeRender(req, res) {
      const logoAsset = await jsreport.documentStore.collection('assets').findOne({ name: 'logo.png' })
      if (logoAsset) {
        req.data.logoAsest  = 'logo.png'
      } else {
        req.data.logoAsest  = 'another.png'
     }
    }
    


  • Hi Jan,

    thanks - didn't thought about that possibility!

    Regards
    Jens


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.