-2

With this code I'm trying to display an event date that has a beginning and ending date, but sometimes there is only one beginning date.

If there is a beginning and ending date i need this displayed: DU 10 JUILLET 2017 AU 10 JUILLET 2017

And if there is only a beginning date, i need this displayed: LE 10 JUILLET 2017 (the "DU" is replace by "LE")

<?php if (isset($this->item->jcfields[3]) && !empty($this->item-jcfields[3])): 
?>Du
<?php echo FieldsHelper::render('com_content.article', 'field.render', 
array('field'=> $this->item->jcfields[3])); ?>
        <?php endif; ?>
        <?php if (isset($this->item->jcfields[7]) && !trim($this->item-
>jcfields[7])): ?>Au
<?php echo FieldsHelper::render('com_content.article', 'field.render', 
array('field'=> $this->item->jcfields[7])); ?>
        <?php endif; ?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Laurent
  • 131
  • 1
  • 11

1 Answers1

1

Untested, and I tried to keep your code the same while improving formatting.

<?php
if (isset($this->item->jcfields[3]) && !empty($this->item->jcfields[3]) && $this->item->jcfields[3]->value != ''):
    if (isset($this->item->jcfields[7]) && !empty($this->item->jcfields[7]) && $this->item->jcfields[7]->value != ''):
        echo "Du ";
    else:
        echo "Le ";
    endif;
    echo FieldsHelper::render('com_content.article', 'field.render', array('field'=> $this->item->jcfields[3]));
    if (isset($this->item->jcfields[7]) && !empty($this->item->jcfields[7]) && $this->item->jcfields[7]->value != ''):
        echo " Au ";
        echo FieldsHelper::render('com_content.article', 'field.render', array('field'=> $this->item->jcfields[7]));
    endif;
endif;
Jo.
  • 778
  • 1
  • 12
  • 17
  • This work when there is begin and ending date but when there is no ending date the disaply is DU 10 JUILLET 2017 AU Thanks. – Laurent Jul 10 '17 at 18:57
  • samr problem when end date is empty DU 6 JUILLET 2017 AU. var dump https://pastebin.com/DBKJsU6X – Laurent Jul 11 '17 at 06:25
  • Yes it work but now when there is no ending date the display is like this LE 1 SEPTEMBRE 2017 AU the AU need to be disable, thanks. – Laurent Jul 11 '17 at 15:48