Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sharing content between sites with wildcard items

Modified: 2008/11/27 14:46 by mark - Categorized as: Sitecore

When you want to share content between multiple sites in a single Sitecore installation, you can create items in a seperate data folder. But if you want to display this content you need to create a seperate item which displays content based upon a querystring parameter. For instance http://mysite/Article.aspx?ArticleID={28f285a0-b213-4e64-a3c4-f92534e1463c}

There is a solution for that, it is called an Wildcard item. A wildcard item is a node in the content tree which matches all http requests on that level. You can create a wildcard item by naming it *.

For instance: I have the following structure in the content tree:

For the wildcard item I create an new template called "Template". On this template I define an Datasource field which has an Droptree fieldtype an a source like /sitecore/content/Home.

In the standard value of the wildcard item I place an sublayout called GetArticle.ascx. The sublayout contains the following code.
Item targetItem;
protected void Page_Load(object sender, EventArgs e)
    Item currentItem = Sitecore.Context.Item;
    string itemName = WebUtil.GetUrlName(0);
    string sourceID = currentItem.Fields["Datasource"].Value;

// Get the central item Item sourceItem = Sitecore.Context.Database.GetItem(new ID(sourceID)); // Find the item by itemName foreach (Item item in sourceItem.Children) { if (item.Name == itemName) { targetItem = item;

} }

// When item is found set datasource of fieldcontrols if (targetItem != null) { Title.DataSource = targetItem.ID.ToString(); Text.DataSource = targetItem.ID.ToString(); } }

Now you can call http://mysite/nieuws/Oudste mens ter wereld overleden.aspx and it returns the content of that item while it is not available at that location in the content tree. In my opinion it is the perfect way to share content and still have understandable urls.

 © Evident Interactive BV