function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SabinaSabina 

LWC: Use the same SVG file in both the bundle .svg and .html files

Hello,

I want to use the same icon both as LWC icon (in the .svg bundle file) and as header icon in the .html file for multiple components. Is there a way to achieve this without duplicating the code?

I can use a static resource for the header icons of multiple componentsm but can't access it in the .svg files. 

Also, can I somehow access the local .svg file into the .html file of the same bundle?

Thank you!
Sabina
Best Answer chosen by Sabina
AnudeepAnudeep (Salesforce Developers) 
Hi Sabina, 

Unfortunately, it is not possible today to access the local .svg file into the .html file of the same bundle. One option would be to create a build script that runs before you deploy that would copy the SVG files from a single source of truth

Also you can try creating a reusable LWC just for svg and you can include it any where you want. However, you cannot add this as LWC icon in the app builder

If the above information helps answer your question, please mark this as Best Answer so that it may help others in the community. Thank You!

Anudeep
 

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Sabina, 

Unfortunately, it is not possible today to access the local .svg file into the .html file of the same bundle. One option would be to create a build script that runs before you deploy that would copy the SVG files from a single source of truth

Also you can try creating a reusable LWC just for svg and you can include it any where you want. However, you cannot add this as LWC icon in the app builder

If the above information helps answer your question, please mark this as Best Answer so that it may help others in the community. Thank You!

Anudeep
 
This was selected as the best answer
SabinaSabina
Thank you, Anudeep!