In a Component Template TBB, you don't have (direct) access to the Page object. The property ContextItem
would return the Component that is being rendered with the current Component Tempalte. Please check that, as I'm not familiar with what TridionHelper
should do.
Hence your code ContextItem as Page
will return null
.
Back to your question -- how to pass metadata from Page Template to Component Template, you could do so using the ContextVariables
, or more generically using Dominic's ContextBag pattern for Tridion. I would probably pass the entire Page
object to the CT TBB.
Anyway, a more important factor to consider here is the question "why do you need Page level metadata in a Dynamic Component Presentation?". DCPs are published and potentially assembled on a Page (at request-time) independent of the Page. So potentially, a visitor would see the DCP on a completely different page (and in different context).
The decision shouldn't be taken lightly and I encourage you to think about it seriously. Most of the times you don't need (and you shouldn't have to make available) Page meta in DCPs, although there are some valid use cases. Please post your thoughts and what you are trying to achieve (maybe in a different question) and I'll try to guide you through that.