3

Does anyone know how to insert images into qute template? I tried to write something in my HTML like:

<img src="../../../resources/templates/imgs/test.jpg" alt=""/>

but always got exception:

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors

and a lot of symbols of image code.

And the same question if image is SVG format.

2 Answers2

3

You shouldn't include images into the templates directory as otherwise they will get parsed by Qute as templates.

Just store the images in a directory outside of the templates directory. If you want them to be accessible as static resources, they should be in src/main/resources/META-INF/resources.

Note that you can also prevent Qute from parsing some files with quarkus.qute.template-path-exclude - https://quarkus.io/guides/qute-reference#quarkus-qute_quarkus.qute.template-path-exclude .

Note: If your are creating web application your relative path of the static assets should be same. For example you are rendering an html file. You have some static assets in that html. Your html path is http://localhost:8080/your-app/v1/product/1. In this example the resource path is your-app/v1/product. So you should place static assets in src/main/resources/META-INF/resources/v1/product

But I don't think that's what you want as in any case, your images need to be accessible as static content.

pvrforpranavvr
  • 2,708
  • 2
  • 24
  • 34
Guillaume Smet
  • 9,921
  • 22
  • 29
  • An example showing the path in the `src` attribute would be helpful. – Codo Dec 09 '21 at 21:04
  • If you haven't defined a root path, files at the root of `src/main/resources/META-INF/resources` will be at `/` so you could just use an absolute URL and it should work. – Guillaume Smet Dec 09 '21 at 22:32
0

Works only variant with base64 : <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ........" alt=""/>