2

enter image description here

I want to link a child item to this folder. So that if any visitor hit the URL pointing to this item, should automatically show the linked item/page.

What would be the best way of achieve this?

I found Aliases as an option. Would it be a good idea to use it ?

2
  • Is the item you want to link can be found anywhere in the content tree? Commented Jan 10, 2018 at 12:06
  • @HishaamNamooya Yes !! Commented Jan 10, 2018 at 12:55

2 Answers 2

5

Quick and clean solution:

  1. Create a new template (called "Folder with default item" or whatever you prefer), inheriting from the standard Folder template
  2. Add a field to your custom folder (e.g. Droptree, and set the Source of the field to query:./*)
  3. Add new httpRequestBegin processor after ItemResolver. Use code (not tested - try and fix if needed):
public class DefaultItemResolver : HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        if (!Context.PageMode.IsNormal || Context.Item == null || Context.Item.TemplateID != DefaultItemFolderTemplateId)
        {
            return;
        }

        Item target = null;

        if (!string.IsNullOrEmpty(Context.Item[DefaultItemFieldIdOrName]))
        {
            target = Context.Item.Database.GetItem(Context.Item[DefaultItemFieldIdOrName]);
        }

        Context.Item = target;
    }
}

Code above return 404 if default item is not selected. If you want to show folder item instead, check if target is not null before assigning it to Context.Item.

2

You could add a General Link field on the Folder template to allow the content editor to select which page it should redirect to by default. You would also need to create a Controller Rendering to handle the redirection and add it to the presentation details of the folder item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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