Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Can a page type be put in a module?

Go to End

4 Posts   796 Views


Community Member, 77 Posts

29 August 2012 at 7:07pm

Edited: 29/08/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.



Community Member, 77 Posts

29 August 2012 at 7:55pm

Edited: 29/08/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

[root]\themes\[my theme]\templates\Layout\

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.


Community Member, 904 Posts

30 August 2012 at 6:53pm

Edited: 30/08/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
	javascript -- folder that contains any required javascript
	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.


Community Member, 77 Posts

30 August 2012 at 8:20pm

Edited: 31/08/2012 8:44am

Thanks banal for the tip regarding Requirements::combine_files.