1

I used the SearchResult component to get items from a template that contains a field called "Related Journeys" from type "tree list". To render it I used a reference in the rendering variant but it renders all related journeys in each item.

I need to render first related journey only, not all. Any help on how I can get the reference in the rendering variant to show only the first reference?

1

No, you can't limit the number of items returned by Variant Reference. It's only possible in Variant Query. The best approach to achieve this would be to write custom token (which can be used in Variant Token item).

Here is an implementation of the existing token $name:

public class ResolveItemName : ResolveVariantTokensProcessor
{
    public override string Token => "$name";

    public override void ResolveToken(ResolveVariantTokensArgs args)
    {
        if (args.ResultControl != null)
        {
            args.ResultControl.Controls.Add(new LiteralControl
            {
                Text = args.ContextItem.Name 
            });
        }
        else
        {
            args.Result = args.ContextItem.Name;
        }
    }
}

This will not give you such flexibility as using Variant Reference because you can put whatever you want under this item. Here you will have hardcoded HTML but you will be able to select from and item just one related journey.

|improve this answer|||||

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.