Skip to main content
added update
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

Package variables (and the package instance) are independent to the Template item, meaning a package variable from a Page Template will not be available to a Component Template, since the latter has its own package instance.

If you want to pass variables between Templates (Page -> Component) you can use a ContextVariable, see also https://code.google.com/p/tridion-practice/wiki/PassContextFromOneComponentRenderToAnother

// in your Page Template
...
engine.PublishingContext.RenderContext.ContextVariables.Add("contextBag", contextBag);

and

// in your Component Template
...
var contextBag = (Dictionary<string, object>)engine.PublishingContext.RenderContext.ContextVariables["contextBag"];

update

I have to add, this is the case for the Modular Templating Framework using DWT TBBs, I'm not a 100% sure this also counts for the Razor Mediator which you are using.

Package variables (and the package instance) are independent to the Template item, meaning a package variable from a Page Template will not be available to a Component Template, since the latter has its own package instance.

If you want to pass variables between Templates (Page -> Component) you can use a ContextVariable, see also https://code.google.com/p/tridion-practice/wiki/PassContextFromOneComponentRenderToAnother

// in your Page Template
...
engine.PublishingContext.RenderContext.ContextVariables.Add("contextBag", contextBag);

and

// in your Component Template
...
var contextBag = (Dictionary<string, object>)engine.PublishingContext.RenderContext.ContextVariables["contextBag"];

Package variables (and the package instance) are independent to the Template item, meaning a package variable from a Page Template will not be available to a Component Template, since the latter has its own package instance.

If you want to pass variables between Templates (Page -> Component) you can use a ContextVariable, see also https://code.google.com/p/tridion-practice/wiki/PassContextFromOneComponentRenderToAnother

// in your Page Template
...
engine.PublishingContext.RenderContext.ContextVariables.Add("contextBag", contextBag);

and

// in your Component Template
...
var contextBag = (Dictionary<string, object>)engine.PublishingContext.RenderContext.ContextVariables["contextBag"];

update

I have to add, this is the case for the Modular Templating Framework using DWT TBBs, I'm not a 100% sure this also counts for the Razor Mediator which you are using.

Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

Package variables (and the package instance) are independent to the Template item, meaning a package variable from a Page Template will not be available to a Component Template, since the latter has its own package instance.

If you want to pass variables between Templates (Page -> Component) you can use a ContextVariable, see also https://code.google.com/p/tridion-practice/wiki/PassContextFromOneComponentRenderToAnother

// in your Page Template
...
engine.PublishingContext.RenderContext.ContextVariables.Add("contextBag", contextBag);

and

// in your Component Template
...
var contextBag = (Dictionary<string, object>)engine.PublishingContext.RenderContext.ContextVariables["contextBag"];