Rss-Feed: CDATA if construct

Hello,

how to use the if construct into CDATA?

plugins/feed/template.php

      <description>
        <![CDATA[<?php  echo strftime('%d.%m.%Y', $item->date());
                        echo $item->{$textfield02}()->kirbytext();
                        //echo thumb($item->image(), array('width' => 300));
                        if(!empty($item->image())) {echo thumb($item->image(), array('width' => 300))};
                        ?>
                ]]></description>

thank you in advance

greetings perry

Like anywhere else. :wink:

But I just saw there’s a syntax error in your code. The last semicolon needs to go inside the if block, not outside, because you need to end the echo call.

Proper indentation helps to find issues like this one:

<description>
<![CDATA[
  <?php echo strftime('%d.%m.%Y', $item->date()); ?>
  <?php echo $item->{$textfield02}()->kirbytext(); ?>
  
  <?php if(!empty($item->image())): ?>
    <?php echo thumb($item->image(), array('width' => 300)); ?>
  <?php endif ?>
]]></description>

PS: Please use Markdown code blocks when posting code in the forum. They use three backticks at the beginning and at the end and not one. That would be for inline code. We change this syntax where it makes sense, but if you post your code like this in the first place, you can save us a lot of work. :slight_smile:

Thank you @lukasbestle

<?php echo 'Thank you @lukasbestle'; ?>
2 Likes

And if you put the backticks in separate lines, that would be even more awesome. :smiley:

<?php echo 'okay'; ?>

2 Likes