AnswerBun.com

Can I pass HTML markup as the content for a LWC slot when used in an Aura component?

Salesforce Asked by Renato Oliveira on December 12, 2020

Currently I have a LWC that has a <slot> inside of it to allow content between the tags. To test said component, I wanted to spin up a scratch org and quickly create a component. Since we can’t create LWC inside the console, I created an Aura component instead.

The markup is similar to this:

<aura:application extends="force:slds">
    <div class="slds-box">
        <c:tokenLocker recordId="5001A0000000000AAA"
                       passTokenToCallbackClass="true">
            <h1>Hello world!</h1>
            <p>Lorem ipsum, dolor</p>
        </c:tokenLocker>
    </div>
</aura:application>

When the LWC tokenLocker displays the content, I simply get an empty div on screen, and no content is displayed at all.

I looked into the LWC documentation and found that in the section “Pass Markup into Slots” there’s this note right at the beginning of the document:

You can’t pass an Aura component into a slot.

I understand that it is not possible to pass an Aura component, but is this valid for simple HTML tags too?

One Answer

In Aura, all HTML components are converted to aura:html components:

A meta component that represents all html elements. Any html found in your markup causes the creation of one of these.

In Aura, you can only pass in other LWC because of this limitation. In LWC, you can use both other LWC and HTML elements equally.

Correct answer by sfdcfox on December 12, 2020

Add your own answers!

Related Questions

Retrieve data from Salesforce using eclipse

1  Asked on December 4, 2020 by bbs_

 

Footer and Visual Force email template

1  Asked on November 30, 2020 by questionasker123

     

“This app can’t be upgraded” in an unmanaged package

1  Asked on November 29, 2020 by user1813867

   

Not able to login to sandbox

1  Asked on November 28, 2020 by amit-visapurkar

 

Parsing through JSON

2  Asked on November 25, 2020 by shreypuranik_pwn

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP