Mark Handy
Mark Handy

Reputation: 1256

Kentico text/xml transformation conditional statmement

I have a transformation, used with a repeater, for a slider. All is working well. I have a slide caption, that isn't required. What I'm struggling with is a conditional statement where the caption tag doesn't show.

Here's my transformation:

<section class="imageSlide">
  <figure role="group">
      <img src="{% SlideImage %}" alt="{% SlideAlt %}">    
      <figcaption><p>{% SlideCaption  %}</p></figcaption>      
  </figure>
</section>

What I'm hoping to do is not render the figcaption if there is no SlideCaption. SlideCaption isn't a required item. I had though if using jquery to change the display type of the <p></p> tags were empty, but want to avoid a lot of DOM manipulation.

I know that the syntax is something like this, but I haven't found a good example I can use as a base solution.

{%  if(....)   %}

Upvotes: 0

Views: 525

Answers (2)

Laura Frese
Laura Frese

Reputation: 331

Another example for future reference if you dont want to be limited to using IfEmpty

   {% if(SlideCaption != "" && SlideCaption != null) { return "<figcaption><p>" + SlideCaption + "</p></figcaption>" } %}

Upvotes: 1

josh
josh

Reputation: 34

Something like this should work. Didn't test it, so may need some tweaks.

{% IfEmpty(SlideCaption, "","<figcaption><p>" + SlideCaption + "</p></figcaption> ")  %}

Upvotes: 2

Related Questions