Silverstripe 3.2:
I have file Header.ss and like to add PHP code on to it?
How I can do that??
Silverstripe 3.2:
I have file Header.ss and like to add PHP code on to it?
How I can do that??
The .ss
suffix means that this is a template file, so PHP code can’t be added to it. If you want to add something into the template generated by PHP you’d need to add something like the following:
In your template:
<div class="somediv">
The time is $MyInterestingThing
</div>
Then in the controller for your site (assuming this is a global header, you’d probably put this in the main Page_Controller.php
class):
public function getMyInterestingThing() {
return date("H:i");
}
SilverStripe automatically makes the connection between the $MyInterestingThing
in the template and the public method getMyInterestingThing()
in the controller.