About Me

My photo
PLANO, Texas, United States

Saturday, October 10, 2020

Access Static Resources

Import static resources from the @salesforce/resourceUrl scoped module. 

A static resource can be an archive file with a nested directory structure. To reference an item in an archive, concatenate a string to create the path to the item, as the example does to build einsteinUrl.


lwcStaticResource.htm


<template>

   <lightning-card title="MiscStaticResource" icon-name="custom:custom19">

       <div class="slds-m-around_medium">

           <img src={imgPhoto} width="500" height="500" alt="Man in car">

       </div>

   </lightning-card>

 </template>


lwcStaticResource


import { LightningElement } from 'lwc';

import lwcPhoto from '@salesforce/resourceUrl/Photo';

export default class LWC_Demo1 extends LightningElement {

   // Expose the static resource URL for use in the template

   imgPhoto=lwcPhoto;

   // Expose URL of assets included inside an archive file

   imageURL = lwcPhoto + '/images/imgphoto.png';

 

}




Note- If you want to run your component in local server, you must have resource in SFDX project. You can simply retrieve your source org. Also, sometimes you may still not be able to see images, in that case, stop the local server and restart.


Access Labels

Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language.

Import labels from the @salesforce/label scoped module. 

LWC_CustomLabel.html


<template>

   <lightning-card>

       {Hello_LWC}

   </lightning-card>

</template>


LWC_CustomLabel.js

import { LightningElement } from 'lwc';

import Hello_CL from '@salesforce/label/c.Hello_LWC';

export default class LWC_Custom_Label_Demo extends LightningElement {

   Hello_LWC1=Hello_CL;

 

}



Access Current User Information

To get information about the current user, use the @salesforce/user scoped module.

import property from '@salesforce/user/property';

import property from '@salesforce/user/property';

The supported properties are Id, which is the user’s ID, and isGuest, which is a boolean value indicating whether the user is a community guest user. Use the isGuest property to check whether or not the user is authenticated.


<template>

   <lightning-card>

       <div>

           <p>User Id:</p>

           {userId}

       </div>

   </lightning-card>

</template>


import { LightningElement } from 'lwc';

import Id from '@salesforce/user/Id';

export default class UserInfomation_Demo extends LightningElement {

   userId = Id;

 

}


No comments:

Post a Comment