Results 1 to 6 of 6

Thread: date format in Calendar

  1. #1
    New user
    Join Date
    07-16-09.
    Posts
    29

    Default date format in Calendar

    Hi there,

    Lots of threads in the forum are about this, but I still can't make it work like I want...

    I want to have the Dutch full date format (5 januari 2011) in my Calendar. In the localconfig.php only numerical formats are allowed. So I changed the event_full.tpl like this:

    Code:
    <?php echo date("j F Y", $this->startDate); ?><?php if ($this->endDate): ?> - <?php echo date("j F Y", $this->endDate); ?><?php endif; ?>
    Works fine, but I get the date in English (5 January 2011). Then I tried:

    Code:
    <?php setlocale(LC_TIME, 'nl_NL'); echo strftime("%d %B %Y", $this->startDate); ?><?php if ($this->endDate): ?> - <?php setlocale(LC_TIME, 'nl_NL'); echo strftime("%d %B %Y", $this->endDate); ?><?php endif; ?>
    Still in English only!

    Yes, my system settings are Dutch and also the resulting HTML-files start with:

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
    What could be the problem?

  2. #2
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: date format in Calendar

    Hi justs,

    you could try this solution. Although the tutorial relates to the news module, I guess the mentioned solution can be implemented in the template of the calendar module as well.
    Contao Community Moderator
    → Support options

  3. #3
    New user
    Join Date
    07-16-09.
    Posts
    29

    Default Re: date format in Calendar

    Thanks xchs,

    It's a good solution, but we're not quite there yet. I put it in the template like this:

    Code:
    <?php preg_match('/([0-9]{2}).([0-9]{1,2}).([0-9]{4})/',$this->date,$date); echo $date[1] . " " . $GLOBALS['TL_LANG']['MONTHS'][$date[2]-1] . " " . $date[3]; ?><?php if ($this->endDate): ?> - <?php preg_match('/([0-9]{2}).([0-9]{1,2}).([0-9]{4})/',$this->date,$date); echo $date[1] . " " . $GLOBALS['TL_LANG']['MONTHS'][$date[2]-1] . " " . $date[3]; ?><?php endif; ?>
    And it works great for the first date (startDate), but the second date (endDate) is not displayed, instead the startDate is displayed there, which makes sense of course. I tried to change the variables
    Code:
    $this->date,$date
    in the preg_match statement to
    Code:
    $this->startDate,$date
    and
    Code:
    $this->endDate,$date
    but that broke the thing.

    Any ideas?

    This issue illustrates that I'm no PHP buff. Sorry about that, but I do think that it should be simpler to make changes to the way dates are formatted in the frontend. I made a feature request in the development forum.

  4. #4
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: date format in Calendar

    Hi justs,

    by adding the following line
    Code:
    <pre><?php $this->showTemplateVars(); ?></pre>
    at the beginning of your modified template you will see all template variables available for this module. Maybe you could there extract some useful information about your desired start and end dates...
    Contao Community Moderator
    → Support options

  5. #5
    New user
    Join Date
    07-16-09.
    Posts
    29

    Default Re: date format in Calendar

    Thank you for replying, xchs. I know what the variables are (startDate and endDate), but I don't know where to put them in the preg_match statement or elsewhere to get the desired result...

  6. #6
    New user
    Join Date
    07-16-09.
    Posts
    29

    Default Re: date format in Calendar

    Aha, by change I discovered the right solution. As always, it's simpler than I thought:

    Just call
    Code:
    $this->parseDate($format)
    instead of
    Code:
    date($format)
    The answer is documented in the tutorial section of the dev website: http://dev.contao.org/projects/typol...ialsMonthNames.
    It's a pity that these great tutorials are hidden so well...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •