umbracoumbraco5

Umbraco 5 Very Basic - How to load an entity in a macro (or actually using a HiveId)?


I've created my first custom Umbraco 5.1 solution. At this point I have a content item ("homepage") with a custom template which has a custom partial macro on it. Now how do I load an entity using the Umbraco helper? I've tried adding several HiveId constructions using a Uri, however I keep getting the same error:

Parameter 'other' must be of type Guid to convert to a Guid CLR type, but it is 'Uri', with value: xxx

Macro partial:

@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework

@{
    //All these fail with the same error message...

    //Based on name:
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("content://Homepage")));

    //Based on path
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("content://p__nhibernate/v__guid/5a4abe489a2e47858bd2a0580180b683")));

    //With custom Hive provider (I've added this using a custom tree/section and products show up, so the hive provider works)
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("custom://products/1")));
}


Solution

  • Why are you creating a Uri?
    The HiveId accepts a string parameter which you can use instead. So does Umbraco.GetContentById(string id)

    I am Umbraco 5 certified and we never used the Uri overload of the HiveId constructor.

    var p = Umbraco.GetContentById("yourStringHiveIdHere"); //(string overload) or 
    var p = Umbraco.GetContentById(new HiveId("yourSringHiveIdHere")); // (HiveId overload)
    

    Also where are you getting your HiveId from?