Awesome! It works!
Thanks for clarifying that. I used Webdoc's code but put it in mysite/code/homepage.php
The filename of mysite/code/homepage.php doesn't have to match the layout filename themes/mytheme/templates/layout/homepage.ss right?
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.
Awesome! It works!
Thanks for clarifying that. I used Webdoc's code but put it in mysite/code/homepage.php
The filename of mysite/code/homepage.php doesn't have to match the layout filename themes/mytheme/templates/layout/homepage.ss right?
No, the filename can be anything. The file itself can be almost anywhere. The project dir can be renamed (from mysite) through the _config.php $project variable.
Templates can be stored in either a theme (themes/<themename>/templates/) or the module (your project is technically a module too! - <mysite>/temlpates)
Just the class name and the template filename must match.
eg. if for instance you had themes/yourtheme/templates/HomePage.ss, then this would be used as the 'main' template, the 'Layout' would then be HomePage or Page, but only if there is a $Layout var present in the 'main'.
In this way templates sort of mirror the class heirarchy in the manner they're searched for/used.
It can be all a bit confusing when you're just getting used to it, but it makes a lot of sense once you do :)