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?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Page 11(current)
- 2
- Next 10 entries
Sorry. Post deleted.
I answered a completely different question.
What?
oops, I understand :) thanks.
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.
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.
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;
}
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.
- Page 11(current)
- 2
- Next 10 entries