4

I have tried the following code in a DWT and the internal link (tridion:href= "@@Links0.Fields.link@@") does not get resolved.

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

When I place this internal link attribute(tridion:href="@@Links0.Fields.link@@") before the onclick, the link get resolved successfully. But page fails at the time of deployment with the following error:

Closing Tag tcdl:ComponentPresentation does not match tcdl:Link Stack: TAG: (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.DefaultTagHandler TAG:ComponentPresentation (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.ComponentPresentationTagHandler TAG:Link (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.LinkTagHandler ------ , Unbalanced tags in TCDL file Closing Tag tcdl:ComponentPresentation does not match tcdl:Link Stack: TAG: (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.DefaultTagHandler TAG:ComponentPresentation (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.ComponentPresentationTagHandler TAG:Link (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.LinkTagHandler

So I found that there is some issue with @@RenderComponentPresentation(Links0.ID,RemoveSpecialCharactersFromTitle)@@ passed as the parameter in Google Analytics.

There are some project limitations, so we are rendering the Component Presentation inside the Google Analytics in the way mentioned above.

When I place the text returned by this Component Presentation, for example, "This is a sample product" it works correctly.

By this I mean the following internal link get resolved successfully:

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

I tried to set the output of this Component Presentation in the RenderContextVariable

@@SetRenderContextVariable("linkTitle_withoutSC", 
  RenderComponentPresentation(Links0.ID,RemoveSpecialCharactersFromTitle))@@

And also tried the following way:

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

But this workaround is not working since we can not set and use RenderContextVariable in the same DWT. Please let me know if I am wrong here.

Now I have been unable to find any other way to deal with the internal link in my situation.

Could somebody help me on this?

EDIT-2 SOME MORE INFORMATION ABOUT THE REQUIREMENT

Point 1- Reason to use @@RenderComponentPresentation(Links0.ID,RemoveSpecialCharactersFromTitle)@@ inside the Google Analytics

Component for this presentation is nested linked component so I can perform my task though a C# TBB or fragment having logic same to RemoveSpecialCharactersFromTitle so I use RenderComponentPresentation here.

Point 2- I am trying to set and use RenderContextVariable in the same DWT of a CT so that it return me the string output[Title] .By this way I can avoid the conflict of tcdl:ComponentPresentation and tcdl:Link tags during the deployment phase.

2 Answers 2

4

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" >
2
  • Thanks for your answer, Could you please validate my understanding that "we can not set and use RenderContextVariable in the same DWT or TBB" ?
    – user584
    Commented Oct 23, 2013 at 8:43
  • Hi Eric, my requirement is something different here. Please see the New Edit in the question and help me. thanks in advance
    – user584
    Commented Oct 23, 2013 at 11:16
2

I think, as you've understood, the code is producing invalid TCDL markup because there is a ComponentPresentation tag within a Link tag's attribute.

I suspect you will need to create a C# TBB which does the same job as your RemoveSpecialCharactersFromTitle Component Template and adds the resulting value to the package.

public class RemoveSpecialCharactersFromTitle : ITemplate
{
     public void Transform(Engine engine, Package package)
     {
          string strippedTitle = "";
          // Get Component from Package/Engine
          // Title stripping code 
          package.PushItem("StrippedTitle", 
                            package.CreateStringItem(ContentType.Text, strippedTitle));
     }
}

This new TBB should then be added to the Compound Template before your Dream Weaver Template. This will enable you to use the value directly in your DWT TBB.

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

I'm curious as to the thinking of using a Component Template for the job of stripping the characters? Is it a legacy template type - VB Script or similar?

1
  • you are correct here.It was my initial thought. But point -1 mentioned in my Edit in the question pushed me to use Component template. Thanks
    – user584
    Commented Oct 23, 2013 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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