Skip to main content
reformatted code to prevent horizontal scrolling
Source Link
Glenn Stevens
  • 1.9k
  • 2
  • 18
  • 33

You can set a Context Variable in a TBB and use it in a Page Template, what you need to do is the following thing.

Instantiate the Context Variable (Page Template)

engine.PublishingContext.RenderContext.ContextVariables.Add("ContextVariable", string.Empty);

Set your context variable in a .NET TBB or C# Fragment (Component Template)

TcmUri linkId = new TcmUri("[Link ID]");
TcmUri templateId = new TcmUri("[RemoveSpecialCharactersFromTitle]");

engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"] = 
                                        engine.RenderComponentPresentation(linkId, templateId);

Put the Context Variable in a Package Variable (Page Template)

stringvar variableconVar = engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"].ToString();
package.PushItem("ContextVariable", package.CreateStringItem(ContentType.Html, variableconVar);

Use the package variable in your DWT (Page Template)

<a onclick="_gaq.push(['_trackEvent', '@@Links0.Metadata.ga_category@@', 
                      '@@Links0.Metadata.ga_action@@', '@@ContextVariable@@']);" 
   tridion:href="@@Links0.Fields.link@@"  target="_blank" class="button primary" >

You can set a Context Variable in a TBB and use it in a Page Template, what you need to do is the following thing.

Instantiate the Context Variable (Page Template)

engine.PublishingContext.RenderContext.ContextVariables.Add("ContextVariable", string.Empty);

Set your context variable in a .NET TBB or C# Fragment (Component Template)

TcmUri linkId = new TcmUri("[Link ID]");
TcmUri templateId = new TcmUri("[RemoveSpecialCharactersFromTitle]");

engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"] = engine.RenderComponentPresentation(linkId, templateId);

Put the Context Variable in a Package Variable (Page Template)

string variable = engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"].ToString();
package.PushItem("ContextVariable", package.CreateStringItem(ContentType.Html, variable);

Use the package variable in your DWT (Page Template)

<a onclick="_gaq.push(['_trackEvent', '@@Links0.Metadata.ga_category@@', '@@Links0.Metadata.ga_action@@', '@@ContextVariable@@']);" tridion:href="@@Links0.Fields.link@@"  target="_blank" class="button primary" >

You can set a Context Variable in a TBB and use it in a Page Template, what you need to do is the following thing.

Instantiate the Context Variable (Page Template)

engine.PublishingContext.RenderContext.ContextVariables.Add("ContextVariable", string.Empty);

Set your context variable in a .NET TBB or C# Fragment (Component Template)

TcmUri linkId = new TcmUri("[Link ID]");
TcmUri templateId = new TcmUri("[RemoveSpecialCharactersFromTitle]");

engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"] = 
                                        engine.RenderComponentPresentation(linkId, templateId);

Put the Context Variable in a Package Variable (Page Template)

var conVar = engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"].ToString();
package.PushItem("ContextVariable", package.CreateStringItem(ContentType.Html, conVar);

Use the package variable in your DWT (Page Template)

<a onclick="_gaq.push(['_trackEvent', '@@Links0.Metadata.ga_category@@', 
                      '@@Links0.Metadata.ga_action@@', '@@ContextVariable@@']);" 
   tridion:href="@@Links0.Fields.link@@"  target="_blank" class="button primary" >
Source Link
Eric Huiza
  • 9.4k
  • 15
  • 28

You can set a Context Variable in a TBB and use it in a Page Template, what you need to do is the following thing.

Instantiate the Context Variable (Page Template)

engine.PublishingContext.RenderContext.ContextVariables.Add("ContextVariable", string.Empty);

Set your context variable in a .NET TBB or C# Fragment (Component Template)

TcmUri linkId = new TcmUri("[Link ID]");
TcmUri templateId = new TcmUri("[RemoveSpecialCharactersFromTitle]");

engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"] = engine.RenderComponentPresentation(linkId, templateId);

Put the Context Variable in a Package Variable (Page Template)

string variable = engine.PublishingContext.RenderContext.ContextVariables["ContextVariable"].ToString();
package.PushItem("ContextVariable", package.CreateStringItem(ContentType.Html, variable);

Use the package variable in your DWT (Page Template)

<a onclick="_gaq.push(['_trackEvent', '@@Links0.Metadata.ga_category@@', '@@Links0.Metadata.ga_action@@', '@@ContextVariable@@']);" tridion:href="@@Links0.Fields.link@@"  target="_blank" class="button primary" >