Postings

You can freely browse the forum and post in the community forum.
However, you need a valid license to write posts for support (own a valid commercial software license or have purchased a support membership).

Posts only show once reviewed. This is mainly preventive to keep spam away. Thank you for your understanding!

Date format for Joomla! custom field

  • Tomoe
  • Tomoe's Avatar Topic Author
  • New Member
  • New Member
More
IP: 80.15.144.202 6 years 1 month ago #5308 by Tomoe
Hi,
I've got a date custom field which is displayed in LNEP view. It's been displayed as "20 octobre 2020" for example, but I would like to show "Mardi 20 octobre 2020". How can I change date format for this custom field only (not for publishing date for example)?
Best regards
  • syw
  • syw's Avatar
  • Administrator
  • Administrator
More
IP: 99.203.186.163 6 years 1 month ago #5309 by syw
Hi, 

The best way to do this is to override the lnep_detail_jfield_calendar.php layout from the components' details folder.

Then you can change the format in that file. It uses the format set in the extension by default. 

You can test by field Id to set the format per custom field.

It does not affect the standard date fields, which use the lnep_detail_date.php layout.

To learn how you can override the layout, please check the documentation.

Olivier.
  • Tomoe
  • Tomoe's Avatar Topic Author
  • New Member
  • New Member
More
IP: 80.15.144.202 6 years 1 month ago #5310 by Tomoe
Thanks syw, that's what I done, but adding a "l" in date format didn't change anything 
Code:
if ($field_data) { echo '<span class="detail_data">'.HTMLHelper::_('date', $field_data, $params->get('d_format', 'l d F Y')).'</span>';} else { echo '<span class="detail_data">-</span>';}
I tried to change drastically date format, suppressing "Y" for example, but nothing changed in date. Override is OK because when I add a css class for example, it's displayed in frontend.
  • syw
  • syw's Avatar
  • Administrator
  • Administrator
More
IP: 24.185.124.166 6 years 1 month ago #5311 by syw
$params->get('d_format', 'l d F Y') retrieves the format that is set in the extension.
'l d F Y' is the default that would be used if there was no value set in the extension.

Therefore, since you want to set a value that is different than the one that is set in the extension, you should not keep $params->get('d_format', 'l d F Y').

Replace 
Code:
HTMLHelper::_('date', $field_data, $params->get('d_format', 'l d F Y'))
with 
Code:
HTMLHelper::_('date', $field_data, 'l d F Y')

Olivier.
  • Tomoe
  • Tomoe's Avatar Topic Author
  • New Member
  • New Member
More
IP: 80.15.144.202 6 years 1 month ago #5312 by Tomoe
Thanks Olivier! I wasn't definitely unable to do this by myself. Your explanation is very clear.
  • syw
  • syw's Avatar
  • Administrator
  • Administrator
More
IP: 24.185.124.166 6 years 1 month ago #5313 by syw
Great! You are welcome :-)

Olivier.