9

I am pushing keywords onto the package with keys like

Keyword1Title

and pulling them out in my DWT using

@@Keyword{$TemplateRepeatIndex}Title@@

The problem is I want to test the contents of the variable (i.e. not empty) before writing the surrounding HTML. Like:

<!-- TemplateBeginIf cond="StringLength(TemplateRepeatIndexBasedKey) > 0" -->
<p>@@Keyword{$TemplateRepeatIndex}Title@@</p>
<!-- TemplateEndIf -->

Followup to Nuno's comment: StringLength(KeywordTemplateRepeatIndexTitle) always returns false.

Is this possible?

  • 1
    Did you try it? I think you can use cond="StringLength(KeywordTemplateRepeatIndexTitle)" in there, due to the order in which it gets evaluated - TemplateRepeatIndex gets converted to the actual value before evaluating the condition - but not sure. – Nuno Linhares Mar 7 '13 at 20:28
  • 1
    Hey Chris, welcome to TridionStackExchange. +1 for the question and thanks for asking (and compelling us to answer to keep 100% answered)! ;-) – Alvin Reyes Mar 7 '13 at 20:36
  • I have tried StringLength(KeywordTemplateRepeatIndexTitle) - always false I to thought this would work, based on my error messages from StringLength(Keyword$TemplateRepeatIndexTitle) - error Sorry for risking the 100% record :) – Chris Morgan Mar 7 '13 at 20:44
  • Maybe the "correct" answer is no :) – Chris Morgan Mar 7 '13 at 20:45
  • 2
    Hi Chris, I dont think this is possible. The problem is you would need to append the TemplateRepeatIndex value with your current variable within the TemplateBeginIf condition. This is not possible as far as I'm aware. One way to work around this is to possibly write a C# tbb that loops through and perhaps remove all empty keys? That way you won't have to do the check for empty string. – user254 Mar 7 '13 at 20:54
7

As Frank mentioned in the comments, there is a lot possible in the cond of a TemplateBeginIf, but I have to say I'm also not quite sure that you can actually check a compound variable like this.

Only thing I can think of right now is to do the check differently, you could write a Custom Function (login required for that link) which will do the check for you. But if I'm not mistaking, the outcome of a Custom Function, can not be used as a condition value, so you would need to add the markup to that as a parameter too. For example something like:

@@MyCheck("Keyword${TemplateRepeatIndex}Title", "<p>{0}</p>")@@

Then in the MyCheck function, you check the package variable for a value and if available write it out. Would work quite well for this example, but if the markup is more complex, might become an issue.

  • I think this is my only option. I had considered a [TemplateCallable] function (it was my last resort), but I was hoping to solve it in DWT. Custom Function! – Chris Morgan Mar 8 '13 at 18:14
1

I worked out something similar as following:

            <!-- TemplateBeginIf cond="'@@${"LinkInternal.LinkInternal".concat(TemplateRepeatIndex)}@@'!=''" -->
            <a  tridion:href="@@LinkInternal.LinkInternal${TemplateRepeatIndex}@@">
            <!-- TemplateEndIf -->
                @@LinkInternal.Image${TemplateRepeatIndex}@@
            <!-- TemplateBeginIf cond="'@@${"LinkInternal.LinkInternal".concat(TemplateRepeatIndex)}@@'!=''" -->
            </a>
            <!-- TemplateEndIf -->

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.