CustomItemGenerator and the Page Editor

108 Views Asked by At

Sitecore 6.6 Update 4

We're using CustomItemGenerator 1.0 and I was using this to help build a primary navigation menu for a site. This worked as expected and everything was rendered properly.

My problem is when I attempt to edit the menu via Page Editor; I don't even see the menu.

I use a repeater and repeat over a list of links to include in the nav. Due to the way the HTML was created, each LI element needs to have its own, specific ID ("Nav Id" Field in Sitecore) that ties into the CSS. Code inside of my repeater's ItemDataBound event:

// Cast the item using CustomItemGenerator-generated class
GenericContentPageItem navItem = (GenericContentPageItem)e.Item.DataItem;

liMenuItem.ID = navItem.NavId.Rendered; // I tried "navItem.NavId" by itself as well

So while this renders properly in the browser, it doesn't when I'm in Page Editor:

<li id="<input id='fld_B72EB6696DCF41A49671972D5EA5DEB8_2163B90C08AB4A18970A7F3ECE79DCFC_en_1_f71bd37d18d146c19e222e89fcffe278_3' class='scFieldValue' name='fld_B72EB6696DCF41A49671972D5EA5DEB8_2163B90C08AB4A18970A7F3ECE79DCFC_en_1_f71bd37d18d146c19e222e89fcffe278_3' type='hidden' value=" Home?="">

... instead of it rendering like this:

<li id="Home">...</li>

Now, that having been said, I can change my code to not use the CustomItemGenerator and it works fine in the browser and Page Editor as follows:

GenericContentPageItem navItem = (GenericContentPageItem)e.Item.DataItem;

Item nav = Sitecore.Context.Database.GetItem(navItem.ID);
liMenuItem.ID = nav.Fields["Nav Id"].ToString();

I would like to avoid having to hardcode field names in my code, which is why I am using CustomItemGenerator. Is there something that I'm doing wrong with my code that it doesn't want to work in Page Editor?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

If you need the actual value out of the field regardless of if you are in the page editor or not, you want to use the Raw property:

liMenuItem.ID = navItem.NavId.Raw;