Accessing Page Template Metadata from a Razor TBB
tridion
Solution
After heading over to Alex's blog to ask the question, I see that he's already answered it for someone else:
Regarding getting Template Metadata out… unfortunately I have not created a wrapper yet for the Template itself, the @Template that is exposed right now is just the Tridion.ContentManager.CommunicationManagement.Template one, which means for now you’ll have to get template fields out the old fashioned way:
@{ Tridion.ContentManager.ContentManagement.Fields.ItemFields templateFields = new ContentManager.ContentManagement.Fields.ItemFields(Template.Metadata, Template.MetadataSchema); }
I’ve added this on my To Do list now though, so you’ll be sure to see a convenience wrapper that will allow you to do @Template.MetaData.YourField in version 1.3.
Problem
Does anyone know if it's possible to read Page Template Metadata from within a Razor TBB? I'm implementing a design that's been built using the 960 grid system and to keep my CT's reusable I was hoping to be able to do something like: ``` <div class="@Page.Template.Metadata.content_grid"> </div> ``` Unfortunately this throws a null reference exception. Is what I'm attempting possible or do I need to write a custom TBB to add this information to the package?