My lightning component –
<aura:component access="GLOBAL" implements="forceCommunity:availableForAllPageTypes,force:appHostable">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<!-- <ltng:require scripts="/resource/jqueryminjs" afterScriptsLoaded="{!c.doInit}"/> -->
<aura:attribute name="articleId" type="String" access="global" />
<forceChatter:feed type="Record" subjectId="{!v.articleId}" />
<p><b>{!v.articleId}</b></p>
</aura:component>
and client controller –
({
doInit : function(component, event, helper) {
var currentArticleUrl = window.location.href;
var articleId = helper.getURLParameter('id');
if (articleId != null) {
console.log('article Id -->', articleId );
component.set("v.articleId", articleId);
}
}
})
Helper code –
({
getURLParameter : function(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
})
Article Id is coming from url parameter. So url can be something like-
https://domain.lightning.force.com/c/TestKnowledgeArticleApplication.app?id=ka07E0000004IVGQA2
I checked that article Id is coming properly on component
tag and client side controller, but the tag even though using the same attribute does not get the value. I am using this in Napili template component.
Best Answer
Unlike force:recordEdit/reviewView the forceChatter:feed component does not support dynamically changing v.subjectId - I just went and looked and there is no logic in the component to trigger reloading the feed when subjectId changes. The component does have a refreshFeed() method but its not marked access="GLOBAL" so no joy there either. Same for the refresh event handler.
All is not lost though - I would switch to using $A.createComponent() inside of your doInit() to construct the feed dynamically - not hard to do - and then your existing container component will work just fine.