1

I have several page templates that use a single page template TBB. The page templates pass a string, version, into the package. The page template TBB evaluates this string via @TridionHelper.Package.GetValue("version") and has some different markup etc. for each one. This works fine.

I want to have some of the components that are used in the page behave differently depending on this variable as well. However, the call to @TridionHelper.Package.GetValue("version"), when used from the component template which is attached to the page returns null. So that package value must not be persisted from the page to the component.

I looked at the Livecontent for SDL Tridion but it's a little sparse on details about the package. My questions are these:

  1. Is there a separate package for each item in a page? Or is there a separate package for PT and CTs? Or is there just one package for each published page?
  2. What is the lifecycle of the package(s)? When does it first get created, what happens to it during the publication process, and when does it die?
  3. If not answered by 1 and 2: Why can't I get access to the value I add in a PT from a CT?

Thanks!

5

The compound templates engine generates an independent package per item, for instance for your page template you have a Package Instance, but for your component template you will have a different Package Instance regardless you are using the same TBB since they are different template instances.

It is possible to access to the Page from the Component templates by using this (it will return a page if you are publishing a page).

Page page = (Page)engine.PublishingContext.RenderContext.ContextItem; 

If you want to pass variables between templates (Page -> Component) you can use a ContextVariable

engine.PublishingContext.RenderContext.ContextVariables.Add("Version", "{version}");

and

string version = engine.PublishingContext.RenderContext.ContextVariables["Version"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.