Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Changing COMMENTS date

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1 2
Go to End
Author Topic: 4138 Views
  • Naely
    Avatar
    Community Member
    4 Posts

    Changing COMMENTS date Link to this post

    I've discovered how to customize the date for posted news articles on my site, however I'm having trouble figuring out how to change the date format for posted Comments. Any input?

  • Tobbe
    Avatar
    Community Member
    25 Posts

    Re: Changing COMMENTS date Link to this post

    Sorry. Post deleted.
    I answered a completely different question.

  • Naely
    Avatar
    Community Member
    4 Posts

    Re: Changing COMMENTS date Link to this post

    What?

  • Naely
    Avatar
    Community Member
    4 Posts

    Re: Changing COMMENTS date Link to this post

    oops, I understand thanks.

  • areikiera
    Avatar
    Community Member
    26 Posts

    Re: Changing COMMENTS date Link to this post

    Make sure you've changed the date formats in:

    sapphire\core\model\fieldtypes\Date.php
    sapphire\core\model\fieldtypes\Datetime.php
    AND
    sapphire\core\model\fieldtypes\SSDatetime.php

    I forgot to change the formats in the last one, and that's the one the Comments section uses.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Changing COMMENTS date Link to this post

    you can also customize how it displays like '12 Feb 2008' or '2 days ago' but making a custom template for the page comments in your theme.

    If you open cms / templates / PageCommentInterface_singlecomment.ss you can see that that is the html for each comment and if you would like to change the overall format of the date you can edit that file. A better idea though, is to copy that file to themes / yourtheme / templates / Includes / and edit it there. Ideally you don't want to edit anything in cms or sapphire as this will make it hard for you to upgrade in the future.

  • dewoob
    Avatar
    Community Member
    10 Posts

    Re: Changing COMMENTS date Link to this post

    For German dates, the Date.Ago function would need to place the word 'vor', the translation of 'ago', *in front of* the timespan, because it says "vor 20 Minuten" in German.

    The _t function needs to be extended to support placeholders. So you could call the _t function with the timespan as a named parameter (was that the idea behind the not-used $context argument?).

    Example:

    Core.php:
    function _t( $entity, $string = "", $priority = 40, $context = "", $values = array() ) {
    // at the end, replace every placeholder in $transEntity by its corresponding value
    }

    Date.php:
    _t( "Date.AGO", " ago", PR_MEDIUM, "", array( 'TIMESPAN' => $this->TimeDiff() ) );

    de_DE.php:
    $lang['de_DE']['Date']['AGO'] = 'vor {TIMESPAN}';

    I'm new to silverstripe, so I don't dare to mess around in the core... but I will try this out in my local installation.

    ---

    I just tried it out, works fine.

    function _t($entity, $string = "", $priority = 40, $context = "", $values = array() ) {
       global $lang;
       $locale = i18n::get_locale();
       $entityParts = explode('.',$entity);
       $realEntity = array_pop($entityParts);
       $class = implode('.',$entityParts);
       if(!isset($lang[$locale][$class])) i18n::include_by_class($class);
       $transEntity = isset($lang[i18n::get_locale()][$class][$realEntity]) ? $lang[i18n::get_locale()][$class][$realEntity] : $string;
       $result = (is_array($transEntity) ? $transEntity[0] : $transEntity);
    foreach( $values as $key => $value ) {
    $result = str_replace( '{' . strtoupper( $key ) . '}', $value, $result );
    }
    return $result;
    }

  • Knastinnot
    Avatar
    Community Member
    1 Post

    Re: Changing COMMENTS date Link to this post

    Hi,

    i'm new to SS, and have a problem.

    For some reason, my SS-Installation won't let me override the SSDatetime-Class.
    Using
    Object::useCustomClass("SSDatetime", "CustomSSDatetime");
    in the _config.php won't do anything.

    Does anyone know why?

    Thanks in advanced.

    4138 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.