Access Content Asset Files
Import content asset files from the
@salesforce/contentAssetUrl scoped module. Convert a Salesforce file into a content asset file to use the file in custom apps and Experience Builder templates.
myContentAsset—A name that refers to the asset file.
contentAssetReference—The name of the asset file.
An asset file name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.
namespace—If the asset file is in a managed package, this value is the namespace of the managed package.
Let’s look at some sample code.
A content asset file 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
goldPartnerLogoUrl. To specify the path to the content asset file in the archive, use the
To reference a resource in a template, use
In a Salesforce DX project, asset files live in the
/force-app/main/default/contentassets directory. You can’t create subdirectories of
contentassets. Create an
.asset-meta metadata file that defines the asset file.
- Lightning Aura Components Developer Guide: $ContentAsset
- Salesforce Help: Find and Create Asset Files in Experience Builder
- Salesforce Help: View and Edit Asset Files
- Metadata API Developer Guide: ContentAsset
- Object Reference: ContentAsset
- @salesforce Modules