Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Page Template Metadata from a Razor TBB

Tags:

tridion

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?

like image 852
richeym Avatar asked May 11 '12 10:05

richeym


1 Answers

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.

like image 93
richeym Avatar answered Nov 01 '22 03:11

richeym