Title says it all. Does a Lightning Component know if it is in a Community or a standard Lightning Salesforce page?
I have a component that implements both the interface for Community as Standard Lightning:
<aura:component implements="forceCommunity:availableForAllPageTypes,flexipage:availableForAllPageTypes,force:hasRecordId" />
I want this component to behave differently depending on if it is on the Community or in standard Lightning. I can solve this by adding an attribute to the component and setting it through the property editor in the Lightning App Builder/Community Builder. But I'm wondering if I can solve this without this attribute.
Best Answer
I have made a blog about how to resolve this issue without having to add a design attribute. Link: http://kevansfdc.blogspot.com/2017/02/does-lightning-component-know-if-it-is.html
The solution I propose is to use a aura enabled method which return whether you are in a site context using the Site class that come natively with Salesforce.
And simply calling this method through an action in Lightning.
Hope this is useful as an answer. Cheers!