Skip to content

Instantly share code, notes, and snippets.

@wernerkrauss
Created June 26, 2014 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wernerkrauss/f03e6ce2d119c0521ffd to your computer and use it in GitHub Desktop.
Save wernerkrauss/f03e6ce2d119c0521ffd to your computer and use it in GitHub Desktop.
Silverstripe: Show next year in Template
---
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
<?php
class NextYearDateExtension extends Extension
{
public function NextYear()
{
return (int)$this->owner->Year() + 1;
}
}
<p>Now: $Now</p> //current date
<p>Now.Year: $Now.Year</p> //current year
<p>Now.NextYear: $Now.NextYear</p> //next year
@wernerkrauss
Copy link
Author

This gist shows how to easily add a NextYear() method to Silverstripe's Date class which you can access e.g. in templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment