Serving image in Thymeleaf template - thymeleaf

I have an email template where I want to serve a static png file, I have tried every possible method, but it is still broken in the email.
src/resources/templates/emailTemplates is the directory for my thymeleaf template file and src/resources/assets is the directory of my logo.png file
This is my html code:
<a target="_blank"
th:href="${WebAppUrl}">
<img
th:src="#{../../assets/logo.png}"
/>
</a>
I have tried adding the src too, tried cid etc. It's still not working.

Related

Generating Mustache Template With Asset Images in Rails

I'm generating a Mustache template within a controller of my rails application. I am able to generate the html just fine. My problem is that I am not able to load in images from the assets folder.
I've tried using ActionController::Base.helpers.image_tag and ActionController::Base.helpers.asset_path and then passing that in as a variable into an image tag in the Mustache template as <img src="{{ asset_path }}" /> for the asset path and the output of the image_tag as it is <div> {{ image_tag }} </div>
I know that image_tag and asset_path are picking up the image because when I put in an incorrect path it outputs an error.
Anybody have any ideas on how to link this image to the Mustache template?
This issue has been resolved. The error was not related to Mustache but to the next phase of the application which is to generate a PDF from the generated HTML.
For reference, I used Rails.root.join('app','assets','..path to image') for the image path.

How to use images on the error pages(404, 500 ...)?

How to use images on the error pages(404, 500 ...)?
Can I use images from a folder "assets" ?
I need to compile them or no?
You can create an image folder within the public folder, in the root of your application, and then from there, you can access them by referencing it directly.
An example on the 404 html file.
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
<img src="images/01.jpg" alt="">
</div>
public/images/ contains the 01.jpg image file.
Another idea that you could consider is having the 404.html and 500.html located on Amazon S3. Something like that would accomplish you having your picture(s) available on S3 with the entire page itself.
Then if you are using a service like Heroku to host your application, you can change the ERROR_PAGE_URL variable to point to your error page on S3.
If you can't or don't want to store the images anywhere else, you can use Base64 encoding to have the images inside the HTML code of the error page itself. You can use any Base64 encoder such as https://base64.guru/converter/encode/image

Using AutoFileName with Sublime Text 2

I have installed the package 'AutoFileName' but when I try to define an img source I recieve only tag options and not images. Does anyone know if I have to define the folder where my images are or where AutoFileName looks for images?
AutoFileName lists files based on the html file you edit. For example, if test1.img, test2.img and test.html are in the same folder, it will list test1.img and test2.img if you are trying to add <img src=""> in test.html.

How to add image in pdf file

I have used this blog for adding a dynamic pdf in my project. when i am tryng to add a image than it is compelling me to have a Image folder in C:\ . How can i add a image from project.
This appears to be using a html view page to render the PDF so you can just use a normal img tag like you would in any html page.
With razor syntax you can do something like this:
<img alt="" src="#Url.Content("~/Content/Images/mypic.png")" />
I believe this may solve your issue. Essentially you want to specify the full web url as the src of the img, for example:
<img alt="" src="www.example.com/images/mypic.png" />

PDFkit doesn't display pictures in PDF

Rails 2, PDFkit 0.5.0
Im generating a PDF from a View in Rails 2 with PDFkit and everything works fine. The only thing which doesn't work is displaying pictures in the pdf.
When I look at the View in the Browser, the picture is there but its missing in the PDF. There is only a placeholder existing in the PDF.
The image_tag is looking like this:
<%= image_tag('plus.gif') %>
I also tried to realize it with a css-file but it doesn't work either.
Any ideas?
Because of the way that wkhtmltopdf works you need to specify the full path to any assets (JS, CSS, images etc), including the domain name.
This won't work:
<img src="/images/foo.png" />
This will:
<img src="http://example.com/images/foo.png" />
One workaround is to set an explicit asset host, even if it's the same server as your app is running on (see the AssetTagHelper documentation for details). Another would be to specify the hostname in the image_tag.
Instead of putting the full path each time, you can add a base tag to the head section.
<base href="http://mydomain.com" target="_blank" />

Resources