22849 Posts in 9674 Topics by 2803 members
|Go to End|
29 August 2012 at 7:07pm Last edited: 29 August 2012 7:58pm
What I am trying to do is to create a PageHolder page type which can be assigned to any page which contains children. Users would typically click on a PageHolder page in a top level menu which would then display summaries of all pages which that page contains.
I would like to separate out the markup and css for this page type by putting it in a module. I see that Tutorial 2 makes an ArticleHolder page type but does not separate out the code.
If this makes any sense and is possible, is there a simple and clean way of doing this? I would like to keep this as simple and clean as possible. Obviously if this module is not simple, and easy to create and implement, there would be no point in doing this.
29 August 2012 at 7:55pm Last edited: 29 August 2012 8:37pm
Sorry, it looks like I have got this sussed now.
I was not seeing an HTML head section in my HTML source when I bowsed a pageholder page. I think this was due to something very basic which I had omitted. I needed to simply add the following template
which just contains
<% include PageHolder %>
Although I think I have now got this sussed, if putting a page type in a module is not a good idea, perhaps someone could advise.
I guess one disadvantage is that separating out the css from layout.css and putting it in a separate file, will increase the number of needed round trips to the server and hence introduce further delay before the user sees the page. As such I think there is a trade off here between modular code and performance. Of course if there was a way in which the content of all the css files could be concatenated after the server receives the initial request and before the browser receives the code, the best of both worlds would be achieved.
30 August 2012 at 6:53pm Last edited: 30 August 2012 6:55pm
Usually a single page doesn't warrant its own module IMHO. But if you like to do that (maybe for easier usage across several sites), then why not?
You're right about the CSS that would create another request to the server... but if it's not a high-traffic site, this shouldn't be an issue. If it turns out to be one, you can still use Requirements::combine_files to combine several CSS files into one.
Your module should have the following file-structure:
code -- folder that contains your code
css -- folder with your css files
templates -- folder with templates required for your module
_config.php -- important. You need this, otherwise SilverStripe won't pick up your code. Can be an empty PHP file
That's it. Create the files (don't forget _config.php) and run dev/build and the framework should pick up your page type from your module.
30 August 2012 at 8:20pm Last edited: 31 August 2012 8:44am
Thanks banal for the tip regarding Requirements::combine_files.
|Go to Top|