Announcement

Collapse
No announcement yet.

How do I refer to one image id in {{imageIds}} in Template

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    sorry been away. glad you found the solution, using AwsS3 would require different config to properly render the image. i think it would be great if they could mention on documentation.

  • shalmaxb
    commented on 's reply
    This is indeed very helpful. I do a lot of trial and error as well, because there are many uncommented possibilities and "do not" in the template creation. I do not use the WYSIWYG anymore at all, because it only produces a mess. And working in HTML code, you must be aware of many things as well. I regularly need ten times as much to get a result as in plain HTML.
    So, every hint or "trick" is really appreciated.

  • rvorsten
    replied
    All,

    I have been doing a lot of trial and error on this today, and finally found a (relatively simple) solution. I wanted to print in my PDF the pictures which I had included in my 'Case' objects.

    The following line shows all attached photo's in the PDF:

    {{#each attachmentsIds}} {{imageTag ./this }} {{/each}}

    Hope this helps somebody!
    Ronald

    Leave a comment:


  • espcrm
    commented on 's reply
    I think you are far more knowledgeable at this point and exhausted all possible method to get it working. When it reach this point, I just go for, "it probably bugged". Perhaps Yuri can give more insight. I will Like the Github and hopefully it raise some attention.

  • jflores
    commented on 's reply
    Ok, I have a solution:

    Instead of using the {{imageTag imageId}} approach, I actually added an image tag with the Object URL hardcoded in the "src" attribute:

    <img src="INSERT_AWS_S3_OBJECT_URL/{{./this}}">

    Of course, there have to be permissions on the bucket that grant read access to the folder so that the system can actually access the resource.

    Given that {{./this}} is appropriately parsing the ID, it further confirms for me that when AWS is the storage mechanism, then the default request isn't correct. Instead, the request root needs to be AWS Object URL, with the {{imageId}} suffixed to the URL.

    I'm open to correction and if my kluge is unnecessary, I'm happy to use a more 'appropriate' response. At a minimum, this approach does require me to let anyone who edits the PDF know that they have to use this Object URL format instead of relying on the helper methods that currently exist "out of the box."

    One suggestion for the development team might be to create another helper method "awsImageTag" that uses the "bucketName" from "config-Internal.php" to create the appropriate baseUrl for the 'src' string. Or maybe add a 'config-internal' setting attribute 'baseObjectUrl' that is referenced as the 'src' prefix when defaultFileStorage is AwsS3. That might be a more scalable implementation (e.g., if someone wanted to use Dropbox vs AWS, for instance). But, I'm purely speculating.

    In either case, I have a kluge that seems to be working for me now and I just wanted to share it with others since there is no error messaging or failure messages that let you know why it's failing if using Aws for storage.

    rabii thank you so much for your help; it prompted me to try a 'clean' install, which is what led me to realize the configuration difference between using the default file system and AWS. Much appreciated!

  • jflores
    commented on 's reply
    Another update to help with troubleshooting.

    If I hardcode an image ID in the code, it will render, even with a 'partial path' (?entryPoint=attachment&id=12345678). But replacing the "id" with {{testImageId}} does not render.

    I also tried adding the full site url as part of the "img src" tag, but that gets stripped out on save.

    The strange thing is that the logic in htmlizer looks like it *should* work and in the URL BASE_URL/?entryPoint=attachment&id={id} renders. It seems like when the PDF rendering is happening that maybe there's a hidden 'file not found' error because the entire URL isn't available? But, if that's the case, then why would putting in a hardcoded ID render, all things equal? Similarly, the {{testImageID}} renders as a string when just put into the code by itself (no imageTag), so why wouldn't handlebars parse it into a string on render?

    I'm not sure the order of operations here, but it does seem like there's a request that turns up 'empty' on render...

    ---EDIT---

    I spoke too soon. Even hardcoding the id doesn't render when the PDF is generated. It does, however, show up in the PDF template editor.

    I think this confirms my suspicion that a request is being made with a partial path, so that when the request is made there is essentially a hidden '404' error on render.
    Last edited by jflores; 12-30-2021, 01:01 AM.

  • jflores
    commented on 's reply
    Ok, I think it's something with using AWS as the storage provider. On the install that had been working, I swapped out the storage to AWS S3 and the ImageTag renderer stopped working. I reset it back to the default file system and it started working again...

    I filed a bug on github: https://github.com/espocrm/espocrm/issues/2188
    Last edited by jflores; 12-30-2021, 12:35 AM.

  • jflores
    replied
    rabii , espcrm - So, I have a clue...I stood up another blank install and got it to work. The difference with the main install I was implementing this on was that the original is using AWS S3 as the storage provider vs. the default file system.

    When I use AWS S3: image doesn't render.

    When I use default storage: image renders.

    Have you guys tried using the PDF imageTag renderer on AwsS3? I'm trying to figure out if it could be my AWS config or if maybe I need to file a bug in github with the PDF image renderer not working with AwsS3 storage provider.

    Or maybe I need to write a new implementation...?

    Thank y'all so much for your help!
    Attached Files
    Last edited by jflores; 12-30-2021, 12:54 AM. Reason: Reference my second comment when trying to get the image to render while using AWS as storage provider.

    Leave a comment:


  • espcrm
    commented on 's reply
    Make sure you click the <> button (code mode view), then paste rabii code in?

  • rabii
    replied
    Hi jflores

    I have tested the code and it worked fine, i am using latest version of espocrm 7.0.8

    Make sure you configure the file / multi-attachment fields to accept img/*

    thanks

    Leave a comment:


  • jflores
    commented on 's reply
    rabii - Thank you for the suggestion, but it still didn't work. Are you also using the most current version of Espo? Do you have any sense about whether there may be anything particular to my environment that I should investigate? I'm baffled b/c even looking at the raw code, it seems like it should be working properly...

  • rabii
    commented on 's reply
    Hi @jflores

    you can try code below:

    Code:
    // Specify some width and height for Image 
    {{imageTag testImageId width=50 height=50}}
    
    // Use ./this without brackets and it should reference each object in the iteration
    {{#each roofPhotosIds}}
        Roof Photo ID: {{imageTag ./this width=50 height=50}}
    {{/each}}
    This code works well for me, i have tested it.

    Cheers

  • jflores
    replied
    I'm on version 7.0.8 and trying to Print to PDF using the most current documentation and this forum. I feel like I must be making some bonehead mistakes....

    This is what I currently have as my tests:

    Fields:
    • Image: testImage
    • Attachment Multiple: roofPhotos

    Code:
    {{imageTag testImageId}}
    
    {{imageTag '61ae3dd11439bb3e4' width=50 height=50}}
    
    {{#each roofPhotosIds}} roof Photo ID: {{imageTag './this'}}{{/each}}
    
    this is test image: <img src="?entryPoint=image&amp;id={{testImageId}}">
    And this is what shows up in my PDF (attached). The `{{#each}}` rendering is what I'm most interested in, the rest are my attempts to just get something to work properly. But, to no avail...

    Attached Files

    Leave a comment:


  • espcrm
    commented on 's reply
    After almost a month, I started using PDF again, and finally manage to get it to work. I am guessing it due to the mod_security issue that I fixed up.

    I can confirm that the code <img style="width: 132.83px; height: 83.95px;" src="?entryPoint=image&amp;id={{landlordSignatureI d}}">
    Work without issue now and finally I can have image in my PDF.

  • espcrm
    commented on 's reply
    I see the <img=src>

    That mean you didn't put that in the code (click the <> button), so right now your template is just a "text" not a code.
Working...
X