I wanted to add an image ( CMS Managed ) to a lightning web component. here does my code look like
TestCMS.html
<template> <img data-contentkey={contentId}> </template>
TestCMS.js
import { LightningElement, api } from 'lwc'; export default class HelloWorld extends LightningElement { @api contentId = ''; }
TestCMS.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="testCMS"> <apiVersion>45.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__RecordPage</target> <target>lightning__HomePage</target> <target>lightningCommunity__Page</target> <target>lightningCommunity__Default</target> </targets> <targetConfigs> <targetConfig targets="lightningCommunity__Default"> <property type="ContentReference" name="contentId" label="Content ID" filter="cms_image"/> </targetConfig> </targetConfigs> </LightningComponentBundle>
I have used ContentReference property as mentioned in the release notes : https://help.salesforce.com/articleView?id=release-notes.rn_experiences_use_cms_in_custom_lwc.htm&type=5&release=230
My intention is to add this page to the community using the experience builder, when you do you can add content from your Salesforce CMS to your custom LWC.
The main query that still remains is that I am able to fetch the content Id of the CMS Content but how to actually refer it on the html ?.