Gazley Posted September 24, 2012 Share Posted September 24, 2012 Hi there, I've read Apeisa's post with great interest. What I'm confused about is his reference to $page->layout - it seems that the template file for every page would be index.php with the specific file specified in $page->layout. Am I correct to assume that he has added 'layout' as a field that is included in each PW template? In Setup/Templates, there is an alternative name that can be specified but each page would require to specify it's own layout value. Am I on the right lines with my understanding? Thanks! Link to comment Share on other sites More sharing options...
Gazley Posted September 24, 2012 Author Share Posted September 24, 2012 Hang-on - re-reading Apeisa's post, it seems that index.php is simply included which kind of answers one part of my question. Still not certain about whether 'layout' is a user-defined field. Link to comment Share on other sites More sharing options...
apeisa Posted September 24, 2012 Share Posted September 24, 2012 Layout could be user defined field. I haven't got the need yet. Layout is more like inner template. All pages have same header and footer, these come from index.php. But then in main section of the site I usually have few different layouts, one for frontpage, two columns, three columns etc. Then if my template doesn't use default one, then I just switch it in template file: $page->layout = "wide"; That setting could easily be user defined if you want client to choose from different content layouts. As you can see, I haven't come up with good term for that inner template. Since pw uses template, I ended up calling it layout. And I set that $page->layout = "wide" in my template code. 1 Link to comment Share on other sites More sharing options...
nik Posted September 24, 2012 Share Posted September 24, 2012 (Ah, Antti was faster, but I'm trying to explain things from another point of view I think. Here goes.) Apeisa is using "first level" of template files as controllers. By "first level" I mean the files that are named after the templates themselves. Then the controllers can specify which layout should be used, giving the possibility to construct output according to some common layouts (frontpage, threeColumns, etc). The file /markup/index.php checks whether $page->layout has been set and uses either the given layout or the default one to render the output. "layout" does not have to be a field in any template as you can set any key to a value in a Page object by saying $page->key = "value". That is equivalent to saying $page->set("key", "value"). Fields in the template assigned to this page can be used in the same way, but as I said, there does not have to be such field defined beforehand. Of course assigning values to keys that don't map to any field in a template doesn't get them saved to the database if $page->save() was called. Hope this clarifies it a bit. 2 Link to comment Share on other sites More sharing options...
Gazley Posted September 24, 2012 Author Share Posted September 24, 2012 So what do you do in each PW template? Do you specify a template name or file? Link to comment Share on other sites More sharing options...
apeisa Posted September 24, 2012 Share Posted September 24, 2012 Thanks Nik, well described. I'm on mobile, so little spare on words. Gazley: you mean on pw admin? My templates are just normal. If I have template called "news-item" I'll let it go to news-item.php. Many times actual template file is very short, sometimes only the included index.php file and chosen layout (if not default). 1 Link to comment Share on other sites More sharing options...
Gazley Posted September 24, 2012 Author Share Posted September 24, 2012 Thanks guys - I think I understand. If I get stuck, I'll come back and ask Cheers! Link to comment Share on other sites More sharing options...
nik Posted September 24, 2012 Share Posted September 24, 2012 Looking at Antti's example of templates/home.php (in his post), he's setting $page->layout to "frontpage". That is the name of a file located in /templates/markup/layouts/, without the ".php" suffix. Then on the very last line in that same file, templates/markup/index.php is included. And that file spots the assigned value "frontpage" at $page->layout, causing it to include the file from template/markup/frontpage.php. Finally frontpage.php uses $page->masthead and $page->main to output a page with a frontpage layout. By the way, "masthead" and "main" aren't probably fields in the template either. Hmm, I wonder if I got you wrong... (Looking at Antti's last response to this thread - he's got some fast fingers on that mobile..) In the example I was trying to lay out, the template "home" would have just a name defined as there is a file at templates/home.php. Well, you're saying you got it already, so maybe I don't have to continue anymore . Link to comment Share on other sites More sharing options...
Gazley Posted September 24, 2012 Author Share Posted September 24, 2012 Hey Guys - this is awesome! I've learned so much and really simplified things. I'm totally blown away with this approach and just how powerful and flexible ProcessWire is! Thanks for all your help and advice! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now