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

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

    I am writing a template and have a quick question that I can find the answer from

    https://www.espocrm.com/documentatio...inting-to-pdf/

    It's possible to print image fields:
    <img src="{{file imageId}}"> where imageId – the name of custom image field, concatenated with the suffix Id.


    when I use the above line it doesn't show any photos, when I use {{imageIds}} it returns 5cbf164eb8f245ae8,5cbf165be263d61e6,5cbf16654f0f60 6d8,5cbf1668e50359b69,5cbf166c60013a7 a3,5cbf187aa2ae037c7,5cbf187ec89466199

    How do I get just the first image id in Template?

    Thanks

  • #2
    {{file imageId}} means the name of the field (image type) where the image is contained concatenated with the string "Id".


    So for example, if you have an entity with a field type IMAGE named "myImage" the template line should be <img src="myImageId"> and this will display the image.

    Espo stores images as files in the data/upload folder and assigns an ID string to refer to them, so the actual content of the "myImage" field is the ID string assigned by the system to the file.

    The reason why you have to concatenate "Id" to the field name is because the actual mysql table field name is "my_image_id"
    Last edited by telecastg; 05-01-2019, 03:21 AM. Reason: Added explanation about image storage

    Comment


    • #3
      Having trouble using this. Just learn about it, I get this error:

      TCPDF ERROR: [Image] Unable to get the size of the image: 5e14147c43d

      Is there a standard type of format of the image that we must use for this to work? This is a .jpg file I'm testing it with. Saved the image from irfanview.

      Comment


      • #4
        I am not familiar with TCPDF errors but I am printing image fields to PDF without a problem using the following code in a template, my image field id is "landlordSignatureId" maybe it can help:

        Code:
        <img style="width: 132.83px; height: 83.95px;" src="?entryPoint=image&amp;id={{landlordSignatureId}}">
        I don't think that the error has to do with the type of image.

        Comment


        • #5
          Originally posted by telecastg View Post
          I am not familiar with TCPDF errors but I am printing image fields to PDF without a problem using the following code in a template, my image field id is "landlordSignatureId" maybe it can help:

          Code:
          <img style="width: 132.83px; height: 83.95px;" src="?entryPoint=image&amp;id={{landlordSignatureId}}">
          I don't think that the error has to do with the type of image.
          Using your code, I stop getting the error and PDF was able to continue being produced. It weird, I cannot get it to work, it just blank where the code is.

          The field type should be "Image" right? So it correct, without using the image code it produce the #ID string so it can retrieve the code but it cannot display image.

          Then I noticed that I been using the Header section, thinking that is the mistake I tried do same code in the Body but it still didn't work.

          I guess I give this up for now.

          Comment


          • #6
            Perhaps you can verify if the image is actually loaded, Espo keeps track of images as "attachments" by creating one attachment record for each file where the record id is the same as the file name.

            The actual file exists in the "data/upload/" folder

            Comment


            • espcrm
              espcrm commented
              Editing a comment
              It work, I can visibly see the image (I add the company logo by using the image field). But I just can't export that logo using Print PDF/PDF Template

          • #7
            In the next version it will be possible use imageTag https://github.com/espocrm/documenta...-pdf.md#images

            Comment


            • #8
              Excellent improvements ! specially the Custom Template Helpers.

              I look forward to 5.8.0 and try to see if "css classes" can be defined as custom template helpers and thus they will be correctly rendered by TCPDF.

              Comment


              • #9
                Someone could support me, in my case the image does not appear
                Attached Files

                Comment


                • espcrm
                  espcrm commented
                  Editing a comment
                  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