5

So we have articles on our website, and we would like to place different profile cards on those items based on their category, which there will only ever be one article type at a time associated with an article. Is there a way to associate profile cards automatically with configuration instead of programmatically building something that can do that?

Example, if we have the Article How to deploy sites with Azure PaaS, and we tagged that article in the Azure category, is there a way we could also assign them to the profile card Azure as well?

5

I wrote this pull request just for this case. It applies profile cards to items based on rules in the rules engine.

https://github.com/Sitecore/Habitat/pull/341

Any rule you can write that analyzes your content, can be applied to this new rules engine to apply a profile to an item on the fly. It does not add it to the item directly. That would require you create a timer job to re-apply your profiles and handle new item added to the tree. What it does it add profile to items and score them during my RunRules pipeline on the item render.

In your case you are going to want to use existing rules or create new rules to evaluate your content based on your tagging. Then execute the proper profile card to be added if your content meets your required tag.

Code

The heart of the code is the ApplyProfileValue class below. When it runs on an item is applies a profile card to an item. The full commit can be found Here

public class ApplyProfileValue<T> : RuleAction<T> where T : RuleContext
{
    public string Profilecardkey { get; set; }

    public override void Apply(T ruleContext)
    {
        Assert.ArgumentNotNull(ruleContext, "ruleContext");
        Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker interaction can not be null.");

        var profileItem = ruleContext.Item?.Database.GetItem(this.Profilecardkey);
        if (profileItem == null)
            return;

        ProcessProfile(profileItem, Tracker.Current.Session.Interaction);
    }

    private static void ProcessProfile(BaseItem profileItem, CurrentInteraction interaction)
    {
        if (profileItem?.Fields[Templates.ProfileCard.Fields.ProfileCardValue] == null) return;

        var trackingFields = new List<TrackingField>
        {
            new TrackingField(profileItem.Fields[Templates.ProfileCard.Fields.ProfileCardValue])
        };

        var fields = (IEnumerable<TrackingField>)trackingFields;

        TrackingFieldProcessor.ProcessProfiles(interaction, fields.FirstOrDefault());
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.