[SalesForce] How to include images from static resources in lightning components used in communities

I am trying to include an image from static resources in a Lightning component. The image is displaying correctly when I use that component in an App. But does not display anything when I use the same component in communities.

The code i am using is :

<img src="/resource/Icon_one" height="30" width="30"/>

Best Answer

Your community will have a URL prefix and you will need to add that prefix as well

<img src="/urlpathprefix /resource/Icon_one" height="30" width="30"/>

You can return this prefix using Netwrok Object record

String urlpathprefix = [Select UrlPathPrefix from Network where Id =:Network.getNetworkId()].UrlPathPrefix 

Try prepending 'sfsites/c/' to you url. No need to query for the base url