salesforcevisualforcesalesforce-lightninglwcaura-framework

Referance a static resource via aura:attribute


I have created a new component and I want to be able to pass an image from a static resource and a custom label via aura:attribute. This is what I tried and it does not work. How can I make the image/text to show?

<aura:attribute name="profileImage" type="string" default="Standard_Profile" />
<aura:attribute name="categoryName" type="string" default="Standard_Name" />

<img src="{!$Resource + !v.profileImage}" alt="profile pic"/>
<h3>{!$Label.'categoryName'}</h3>

I am very new to Salesforce.


Solution

  • Map the values from your custom label and static resource as default values in the attributes and use it in the code

    <aura:component implements="flexipage:AvailableForAllPageTypes">
        <aura:attribute name="profileImage" type="string" default="{!$Resource.profileImage}" />
        <aura:attribute name="categoryName" type="string" default="{!$Label.c.categoryName}" />
        
        <!-- Stand-alone static resources image file-->
        <img src="{!v.profileImage}"/>
        
        <!-- custom label -->
        <div>
            {!v.categoryName}
        </div>
    </aura:component>