Adding custom navigation

To add your own navigation capability, create a Lightning Component that extends forceCommunity:navigationMenuBase. The code snippet to get started is given in the following code. Note that {!v.menuItems} automatically adds the menuItems, which was configured in the navigation menu by the community admin. Take a look at this code block:

<aura:component extends="forceCommunity:navigationMenuBase">
<div class="slds-grid slds-grid--vertical slds-navigation-list--vertical">
<ul onclick="{!c.onClick}">
<aura:iteration items="{!v.menuItems}" var="item">
<li class="{!item.active ? 'slds-is-active' : ''}">
<a href="javascript:void(0);" data-menu-item-id="{!item.id}" class="slds-navigation-list--vertical__action slds-text-link--reset">
{!item.label}
</a>
</li>
</aura:iteration>
</ul>
</div>
</aura:component>

The controller code is as follows:


({
onClick : function(component, event, helper) {
var id = event.target.dataset.menuItemId;
if (id) {
component.getSuper().navigate(id);
}
}
})

If you are in communities built from one of the Salesforce provided templates, you can override the search and the profile menu using the theme settings of the builder, as shown in the following screenshot:

The possibilities with the Community Cloud are huge, and knowing how to leverage custom Lightning Components in the builder to customize the user experience can make your communities user-friendly and easy to use. To get more insight into the events and components available, refer to the documentation at https://developer.Salesforce.com/docs/atlas.en-us.communities_dev.meta/communities_dev/communities_dev_basics_supported.htm.

Finally, note that you can use Salesforce Dx to create scratch Orgs with communities enabled and communities deployed.

The config folder needs a file called project-def.json, as shown in the following code:

{
"OrgName": "mohith Company",
"edition": "Developer",
"OrgPreferences" : {
"enabled": ["S1DesktopEnabled","NetworksEnabled"]
},
"features": ["Communities"]
}

You can run the following commands if you have a Salesforce DX set up to create a scratch Org with communities enabled, as shown in the following code:

//Clone the source from the git repo

git clone https://github.com/PacktPublishing/Learning-Salesforce-Lightning-Application-Development.git

//CD into chapter 12
cd chapter12

//Create a scratch Org
sfdx force:org:create -s -f config/project-scratch-def.json -a testOrg

//Set as the Default for push and pull
sfdx force:config:set defaultusername=testOrg

//Push the source code to the scratch Org
sfdx force:source:push


Note that you may get some errors regarding guest users that can't be found. This is expected. After creating a community, navigate to scratch Org and Community Builder, and publish the community.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.28.108