Jump to:

22979 Posts in 11760 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Can a page type be put in a module?

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

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

Page: 1
Go to End
Author Topic: 270 Views
  • simples
    Avatar
    Community Member
    76 Posts

    Can a page type be put in a module? Link to this post

    Hi,

    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.

    Thanks.

  • simples
    Avatar
    Community Member
    76 Posts

    Re: Can a page type be put in a module? Link to this post

    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\PageHolder.ss

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Can a page type be put in a module? Link to this post

    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:

    ModuleFolder
       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.

  • simples
    Avatar
    Community Member
    76 Posts

    Re: Can a page type be put in a module? Link to this post

    Thanks banal for the tip regarding Requirements::combine_files.

    270 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.