Images for custom webcomponent #7262
-
Hi, Is there a way for me to store an image file locally in a custom webcomponent? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello @akshilverma can you show us how you refer to the svg file, it should be imported in order to be bundled. |
Beta Was this translation helpful? Give feedback.
-
I have placed the svg file inside an images folder (inside src folder, src/images/logo.svg). After this I am trying to directly consume it using the img tag in a .hbs file. |
Beta Was this translation helpful? Give feedback.
-
Hello @akshilverma the best way is to include the svg directly in the template, f.e: Component.hbs <div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g role="presentation">
<path d="M370 370q13 0 20.5 8t7.5 21q0 28-28 28h-29q-28 0-28-28 0-13 7.5-21t20.5-8h29zm-12-127q56 21 90.5 70.5T483 427v57q0 28-28 28H57q-28 0-28-28v-57q0-64 34.5-113.5T154 243q-40-40-40-100 0-30 11-55.5t30.5-45 45-30.5T256 1t56 11 45 30.5 30 45 11 55.5q0 60-40 100zM256 58q-36 0-60.5 24.5T171 143q0 37 24.5 61t60.5 24 60.5-24 24.5-61q0-36-24.5-60.5T256 58zM86 453h142V350l-20-19q-8-9-8-20.5t8-19.5l6-6q-27 3-50 15.5t-40.5 31-27.5 43T86 427v29-3zm340-23q0-28-10-52.5t-27-44-40-31.5-50-14l5 6q9 8 9 19.5t-9 19.5l-19 20v103h141v-26z">
</path>
</g>
</svg>
</div> This should work right? The other approach with having the svg file, copied into the dist, then used via import also will work but not with all build tools. |
Beta Was this translation helpful? Give feedback.
Hello @akshilverma the best way is to include the svg directly in the template, f.e:
Component.hbs