Skip to main content
TemplateRepeatIndex, not TemplateBeginRepeat...
Source Link
Nuno Linhares
  • 29.1k
  • 3
  • 42
  • 91

I disagree with you - I do think that in this case is perfectly OK to educate editors that their titles cannot contain a quote - but obviously you still need to validate this and do the best possible.

You could:

  • Do a post-processing C# template building block with a decent RegEx (always fun) to find this quote and replace it with, for instance '
  • Change the content in the package before you read it with a c# TBB (you can use a TBB to modify the content of a component in the package, just don't try to save it or make changes that would make the component invalid according to its schema) - bit rusty here, but you may have to use the XML of the component to do this instead of the Component class
  • Use a pre-DWT c# template building block that loads your collection of videos, escapes their titles correctly - either with a replace or with something like System.SecurityElement.Escape (not 100% sure it helps you here, but worth a try) - then push the modified values to the package with a name like escapedTitle_x where _x represents the position of this title in the collection - if it matches your TemplateBeginRepeatTemplateRepeatIndex (which it should if you start with 0) then you can use something like this in your DWT:
<!-- TemplateBeginIf cond="Component.Schema == 'Video Collection'" -->
  <a onclick="_gaq.push(['_trackEvent', 'XYZ', 'ABC', '@@escapedTitle_${TemplateRepeatIndex}@@']);"  href="@@List${TemplateRepeatIndex}.Fields.link@@" target="_blank">
    @@escapedTitle_${TemplateRepeatIndex}@@
  </a> 
<!-- TemplateEndIf -->

I disagree with you - I do think that in this case is perfectly OK to educate editors that their titles cannot contain a quote - but obviously you still need to validate this and do the best possible.

You could:

  • Do a post-processing C# template building block with a decent RegEx (always fun) to find this quote and replace it with, for instance &#39;
  • Change the content in the package before you read it with a c# TBB (you can use a TBB to modify the content of a component in the package, just don't try to save it or make changes that would make the component invalid according to its schema) - bit rusty here, but you may have to use the XML of the component to do this instead of the Component class
  • Use a pre-DWT c# template building block that loads your collection of videos, escapes their titles correctly - either with a replace or with something like System.SecurityElement.Escape (not 100% sure it helps you here, but worth a try) - then push the modified values to the package with a name like escapedTitle_x where _x represents the position of this title in the collection - if it matches your TemplateBeginRepeat (which it should if you start with 0) then you can use something like this in your DWT:
<!-- TemplateBeginIf cond="Component.Schema == 'Video Collection'" -->
  <a onclick="_gaq.push(['_trackEvent', 'XYZ', 'ABC', '@@escapedTitle_${TemplateRepeatIndex}@@']);"  href="@@List${TemplateRepeatIndex}.Fields.link@@" target="_blank">
    @@escapedTitle_${TemplateRepeatIndex}@@
  </a> 
<!-- TemplateEndIf -->

I disagree with you - I do think that in this case is perfectly OK to educate editors that their titles cannot contain a quote - but obviously you still need to validate this and do the best possible.

You could:

  • Do a post-processing C# template building block with a decent RegEx (always fun) to find this quote and replace it with, for instance &#39;
  • Change the content in the package before you read it with a c# TBB (you can use a TBB to modify the content of a component in the package, just don't try to save it or make changes that would make the component invalid according to its schema) - bit rusty here, but you may have to use the XML of the component to do this instead of the Component class
  • Use a pre-DWT c# template building block that loads your collection of videos, escapes their titles correctly - either with a replace or with something like System.SecurityElement.Escape (not 100% sure it helps you here, but worth a try) - then push the modified values to the package with a name like escapedTitle_x where _x represents the position of this title in the collection - if it matches your TemplateRepeatIndex (which it should if you start with 0) then you can use something like this in your DWT:
<!-- TemplateBeginIf cond="Component.Schema == 'Video Collection'" -->
  <a onclick="_gaq.push(['_trackEvent', 'XYZ', 'ABC', '@@escapedTitle_${TemplateRepeatIndex}@@']);"  href="@@List${TemplateRepeatIndex}.Fields.link@@" target="_blank">
    @@escapedTitle_${TemplateRepeatIndex}@@
  </a> 
<!-- TemplateEndIf -->
Source Link
Nuno Linhares
  • 29.1k
  • 3
  • 42
  • 91

I disagree with you - I do think that in this case is perfectly OK to educate editors that their titles cannot contain a quote - but obviously you still need to validate this and do the best possible.

You could:

  • Do a post-processing C# template building block with a decent RegEx (always fun) to find this quote and replace it with, for instance &#39;
  • Change the content in the package before you read it with a c# TBB (you can use a TBB to modify the content of a component in the package, just don't try to save it or make changes that would make the component invalid according to its schema) - bit rusty here, but you may have to use the XML of the component to do this instead of the Component class
  • Use a pre-DWT c# template building block that loads your collection of videos, escapes their titles correctly - either with a replace or with something like System.SecurityElement.Escape (not 100% sure it helps you here, but worth a try) - then push the modified values to the package with a name like escapedTitle_x where _x represents the position of this title in the collection - if it matches your TemplateBeginRepeat (which it should if you start with 0) then you can use something like this in your DWT:
<!-- TemplateBeginIf cond="Component.Schema == 'Video Collection'" -->
  <a onclick="_gaq.push(['_trackEvent', 'XYZ', 'ABC', '@@escapedTitle_${TemplateRepeatIndex}@@']);"  href="@@List${TemplateRepeatIndex}.Fields.link@@" target="_blank">
    @@escapedTitle_${TemplateRepeatIndex}@@
  </a> 
<!-- TemplateEndIf -->