Results 1 to 8 of 8

Thread: $this->date outputs different formats

  1. #1
    User
    Join Date
    08-15-09.
    Location
    Sweden
    Posts
    82

    Default $this->date outputs different formats

    It seems that when using $this->date to output the date of an calendar event, the output is different regarding which template is used.

    For example:
    In my event_upcoming.tpl $this->date outputs: 2010-01-10
    In my event_default.tpl $this->date outputs: 2010-01-10 (10:00 - 11:00)

    Shouldn't $this->date output the same date format?

    Anyway, this gives me some problem, because I want to format the time and date to this format (Swedish):
    Söndag 10 Januari – Kl 10:00 - 11:00

    I have managed to accomplish this in my event_upcoming.tpl by using this code:
    Code:
    <div class="date"><span class="date">
    <?php echo $this->parseDate("l j F", strtotime($this->date)); ?></span>
    <?php if ($this->time): ?> – Kl <span class="time"><?php echo $this->time; ?></span><?php endif; ?>
     </div>
    But I can't really get it to work in my event_default.tpl. Because the date format of $this->date is different in this template, I cannot use the same code.

    I found this tutorial on how to separate time and date fields, but it doesn't work. It gives the following error:
    Code:
    Warning: date_format() expects parameter 1 to be DateTime, boolean given in /public_html/templates/event_default.tpl on line 5
    Anyone knows how to get this to work?
    And also why the default date format is different in different templates?

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: $this->date outputs different formats

    Hey Ola,

    I think most of the modules spit out a "$this -> tstamp" or "$this -> timestamp" as well (I know the news ones do, so the event ones probably do as well). I would try those next -- if either work, you can run it through the date() function to get it into any format you need.

    Brian
    Brian

  3. #3
    User
    Join Date
    08-15-09.
    Location
    Sweden
    Posts
    82

    Default Re: $this->date outputs different formats

    Thanks for the suggestions.
    I tried them, but it seems like that $this->timestamp just outputs todays date, and $this->tstamp just outputs the date that the event was created.

    So no luck yet.

    Is there a way to see all properties of a single event that can be used with $this->...?

  4. #4
    Official Contao Team
    Join Date
    06-10-09.
    Location
    Stuttgart, Germany
    Posts
    68

    Default Re: $this->date outputs different formats

    Hi Ola,

    jus a second to find the code you can use in templates...

    10 seconds later :-)

    You can replace
    Code:
    <?php echo $this->date; ?>
    with
    Code:
    <?php echo $this->parseDate("d.m.Y", $this->time); ?>
    and set your date / time putput by adding it in the command like
    Code:
    d.m.y - H:i
    .

    Using this
    Code:
    <?php echo $this->date; ?>
    will grab your date & time definitions you made in settings.
    ---------------------------------------------------
    kind regards planepix

    Official Contao team member - Official Contao partner
    workshop contao conference site 2011
    workshop contao conference site 2012

  5. #5
    User
    Join Date
    08-15-09.
    Location
    Sweden
    Posts
    82

    Default Re: $this->date outputs different formats

    Quote Originally Posted by planepix
    You can replace
    Code:
    <?php echo $this->date; ?>
    with
    Code:
    <?php echo $this->parseDate("d.m.Y", $this->time); ?>
    and set your date / time putput by adding it in the command like
    Code:
    d.m.y - H:i
    .
    Doesn't work. $this->time outputs nothing at all.

    Quote Originally Posted by planepix
    Using this
    Code:
    <?php echo $this->date; ?>
    will grab your date & time definitions you made in settings.
    Nope, doesn't work. I changed the settings in backend and removed the timestamp, but no change on the output.


    Did a test to show you how the output render an event in my two templates:
    The date/time setting in backend was just Y-m-d. (Not the default Y-m-d H:i)

    event_upcoming.tpl (module that renders the upcoming five events):
    $this->date; outputs 2010-01-11
    $this->time; outputs 18:00 - 20:00

    event_default.tpl (module that renders a single event):
    $this->date; outputs 2010-01-11 (18:00 - 20:00)
    $this->time; outputs [nothing]

    Is this difference a feature or a bug?

    So, my problem is, I don't now how to render the date, without the timestamp in my event_default.tpl template. Suggestions are welcome!

  6. #6
    User
    Join Date
    06-19-09.
    Location
    Elbl?g, Poland
    Posts
    152

    Default Re: $this->date outputs different formats

    Quote Originally Posted by Ola
    So, my problem is, I don't now how to render the date, without the timestamp in my event_default.tpl template. Suggestions are welcome!
    Try this:
    add at the bottom of your event_default.tpl
    [code=php:1pekg3ns]<span class="syntaxhtml"><pre><?php*$this->showTemplateVars();*?></pre></span>[/code:1pekg3ns]
    reload page, see which variable have timestamp and next:
    [code=php:1pekg3ns]<span class="syntaxhtml"><?php*echo*date("d/m/Y",*$this->startDate);*?></span>[/code:1pekg3ns]
    of course in this case I assume that "startDate" is timestamp
    Marcin

    http://www.contao.pl - Polish Support Site
    http://forum.contao.pl - Polish Contao community forum


    -----------------------
    Need custom template? Feel free to contact me by e-mail marcin@contao.pl

  7. #7
    User
    Join Date
    08-15-09.
    Location
    Sweden
    Posts
    82

    Default Re: $this->date outputs different formats

    Quote Originally Posted by qrczak
    Try this:
    add at the bottom of your event_default.tpl
    [code=php:1g6vdtq7]<span class="syntaxhtml"><pre><?php*$this->showTemplateVars();*?></pre></span>[/code:1g6vdtq7]
    Woohoo, you are my hero! I finally found out. Thanks qrczak! :D

  8. #8
    Official Contao Team
    Join Date
    06-10-09.
    Location
    Stuttgart, Germany
    Posts
    68

    Default Re: $this->date outputs different formats

    Nice to know you find a solution Ola.
    ---------------------------------------------------
    kind regards planepix

    Official Contao team member - Official Contao partner
    workshop contao conference site 2011
    workshop contao conference site 2012

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
  •