Hi @all
is it possible to control subpages like this?
<% if date < 01.01.2009 %>
Template 1
<% else %>
Template 2
<% end_if %>
Thanks
Benni
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Hi @all
is it possible to control subpages like this?
<% if date < 01.01.2009 %>
Template 1
<% else %>
Template 2
<% end_if %>
Thanks
Benni
Hmm I don't think you can use operator in the template if statements, but you could always create a method on your Page. This is assuming you're trying to just render the certain page itms in a template differntly
function OldPage() {
$date = $this->Date;
if ($date->Year() < 2009){
return true;
} else {
return false;
}
}
<% if OldPage %>
<% else %>
<% end_if %>
If you're trying to use a totally different page templates to render older pages just use the date check in your page index function
public function index() {
$date = $this->Date;
if ($date->Year() < 2009){
return $this->renderWith("OldPage");
} else {
return Array();
}
This will render old pages with OldPage.ss while new pages with the default
i think the first option should work. i'll try it now and post my result in a view minutes :)
hmm it didn't work. but i think i know why. because i'll use the function? if control? (don't know the right name) on the parent page? the date is written in a child page.
this is the code:
ReferencePage.php http://pastie.org/2286299 - where the date is saved
ReferencesPage.php http://pastie.org/2286316 - where i want to use the seperation by date
ReferencesPage.ss http://pastie.org/2286319
i put your function in the ReferencePage.php and then i tried to use it inside <% control Children %>
but it didn't work :(
EDIT// can i also use the function like this
function OldPage() {
$date = $this->Date;
if ($date->Year() =< 2009){
return true;
} else {
return false;
}
}
so everything with was saved in 2009 and before ?
EDIT2// The final Page should look like this:
------------------------------------------------------------------
- All References -
- -
- ########################## -
- After 2009 -
- New Ref 1, New Ref 2, New Ref 3, ... -
- ########################## -
- -
- ******************************** -
- Before 2009 -
- Old Ref1, Old Ref2, Old Ref3, ... -
- ******************************** -
- -
-----------------------------------------------------------------
My Fault, the Date Field isn't saved as Date Object this is teh function you need to use
function NewPage(){
$date = substr($this->ReleaseDate, 0, 4);
if ($date >= 2009){
return true;
} else {
return false;
}
}
Put that in your RefrencePage (not in the RefrencePage_controller)
then in RefrencesPage.ss you can use
<% control Children %>
<% if NewPage %>
New Refrence COde
<% else %>
Old Refrence Code
<% end_if %>
<% end_control %>
what should i put in which string? how can i change the dateformat to DA.MO.YE ?
// At the moment it doesn't work :/ the output is always the whole references :(
If you change the date format you will need to change the substr() function.
DateFormat is set at the User Level, but I'm not sure if you change the content authors Date setting if it will save the data in the revised format or just output differently to the end user
http://doc.silverstripe.org/sapphire/en/topics/configuration
EDIT
Just did a quick check and my date is up as MO/DA/YEAR but the Date field saves as YEAR-MO-DA
But you can use $Date.NiceUS to change it in the template
Have you read my edit?
// At the moment it doesn't work :/ the output is always the whole references
in the admin interface my date output is DD-MO-YYYY. could this be the problem?