-
-
Save wernerkrauss/f03e6ce2d119c0521ffd to your computer and use it in GitHub Desktop.
Silverstripe: Show next year in Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Name: mysite | |
After: | |
- 'framework/*' | |
- 'cms/*' | |
--- | |
# YAML configuration for SilverStripe | |
# See http://doc.silverstripe.org/framework/en/topics/configuration | |
# Caution: Indentation through two spaces, not tabs | |
SSViewer: | |
theme: 'simple' | |
Date: | |
extensions: | |
- NextYearDateExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NextYearDateExtension extends Extension | |
{ | |
public function NextYear() | |
{ | |
return (int)$this->owner->Year() + 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Now: $Now</p> //current date | |
<p>Now.Year: $Now.Year</p> //current year | |
<p>Now.NextYear: $Now.NextYear</p> //next year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist shows how to easily add a NextYear() method to Silverstripe's Date class which you can access e.g. in templates.