Friday 20 November 2015

How to show an image from static resource in Lightning Component Salesforce

We are using apex:image tag to show an image in Visualforce page. However referring image in lightning component is slightly differ from Visualforce page. 

Here is the example for how to show or refer an image from static resource file in lightning component,

Example

  1. <aura:component >
  2.     <img src="http://www.robotmag.com/images/frontpage.jpg"/>
  3. </aura:component>

Directly referred public image from online source.

Resource Example

  1. <aura:component >
  2.     <img src="/resource/ImageLibrary" height="50" width="200"/>
  3. </aura:component>

Where "ImageLibrary" is the Static Resource name.

Zip Resource Example

  1. <aura:component >
  2.     <img src="/resource/ImageLibrary/images/techno.jpg" title="Welcome to tech world"/>
  3. </aura:component>

ImageLibrary - Static Resource name.
images - Folder name.
techno.jpg - Image file name.

Note: Referring Folder name and file name is case sensitive.

4 comments:

  1. I have multiple images and I need to display the correct one based on the Status field. Any thoughts on how I could add some conditional logic to display the right image?

    for example if c.status = new, i want the component to display NEW.jpg, but if c.status = OLD I want to display OLD.jpg.

    thoughts?

    ReplyDelete
    Replies
    1. Did you builded this logic? If yes cpuld you please share us the info

      Delete
  2. this can be done using aura:if, like you can call the new one in the if condition and the old one in the else part

    ReplyDelete
  3. can we check condition in js controller? can any give me example or snippet for this

    ReplyDelete

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...