paulg Posted January 19, 2014 Share Posted January 19, 2014 Hi All Day 1 for me with processwire as I was introduced to it by a friend a couple of days ago and have to say (being used to doing most things in drupal) I cant believe how easy this is to use and im hooked already, I can see it fast becoming my cms of choice for a lot of things I do currently. So time to ask my first question to help with my learning. Are there any tutorials or examples out there I can read to figure out how i can link associated data. For example i d like to create a page for a record relating to a staff member and then when i view the staff member see a table view below showing all their qualifications and skills, if possible several tabs with different data but i ll figure that out later unless theres a tutorial that already explains this as well. Hope that makes sense Many thanks in advance and im looking forward to hopefully contributing back as I learn process wire Paul 1 Link to comment Share on other sites More sharing options...
Mats Posted January 19, 2014 Share Posted January 19, 2014 Welcome Paul! Check out the Page field type: http://processwire.com/videos/page-fieldtype/ /Mats 2 Link to comment Share on other sites More sharing options...
paulg Posted January 19, 2014 Author Share Posted January 19, 2014 Thanks for the quick reply, i ll have a look regards Paul Link to comment Share on other sites More sharing options...
wilsea Posted January 20, 2014 Share Posted January 20, 2014 I'm new to PW as well, but here goes....pagesThis is how I understand it at the moment. The biggest conceptual shift is moving away from the idea that pages are web pages. In PW they are more than that. Pages hold data, so think of pages as more like records in a database. Exactly what data the page has depends on the template the page is using. When you create a new page, the first thing you do is choose a template for the page.templates.(1) Templates keeps track of what data items will be stored with each page eg name, position, phone etc. Each template uses one or more fields, and you decide which fields when you create the template. (These fields can be changed later on, if you wish, but obviously deleting a field will also lose the data associated with that field ). The data is collected when you fill in a form on the admin panel for each staff member, or if you already have a lot of data you can import the data as a csv file using the Import Pages from CSV module, You can have as many templates as you like, and fields can be re-used in multiple templates.(2) the template usually has a php file of the same name in site/templates that manages how the data is displayed. The template php file is where the code goes to produce a simple vanilla display of data, or can get as fancy as you like with tables, tabs, and whatever collection of whistles and bells you like. Each template has access to the $page variable that comes with PW, which can be used to refer to each item of data (ie the fields in the template) on your page, using syntax $page->myvariable to refer to the data in the field. eg If the page had a field first_name, then echo $page_>first_name would print the first name of the person associated with the page. Ryan explains it really well at http://processwire.com/talk/topic/43-template-tutorial/ (3) templates are created from admin>setup>templates>new template. This is where the fields are connected to the template (and to pages using the template). The php file manages the display of the page. It doesn't seem to matter whether you create the php file and import it into templates first, of whether you create a template first without a matching file and ad the file later.To display a page for Fred Nurk, you would have a page using a template with fields for name, phone and whatever else you want to record, and a template php file, with the same name as the template. If your template was called staff, you would also have a file staff.php, in site/templates. If the page for Fred was under a subdirectory called employees, and the title field was used for his name, then the page could be viewed at yoursite/employees/fred-nurk/ fields fields are containers for information. Fields need to exist before they can be added to a template. Fields are created from admin>setup>fields.new field. Each template has a mandatory title field, which is used to when a page is displayed in the pages directory tree. It's also usually used to build the url address that will be used to view the page.Getting information in a page from other pagesYou can get information into a currently displayed page from another PW page, by using the $pages variable and any selector that seems appropriate. There a number of different selectors that let you locate a particular page or group of pages by a wide range of criteria. The API section on Selectors is a must read and reread.(It's a lengthy page full of essential information and I found it took a while to take it all in - it might be worth printing it out ) The selectors take all the pain out of querying the database .For example, selectors might be used to set up a loop through each of the staff member pages (remember pages are like database records) and generate a list of phone numbers on one page.If you're keeping things like skills on separate pages, then you can use a selector to get information about the skill, and add that to your page on Fred Nurk. In your template php file you would use a selector to locate a page or group of pages, eg $myfoundpage=$pages->get(some selection criteria) or $myPagesArray = $pages->find (some selection criteria), and then you have access to all the fields associated with $myfoundpage through its template. If the template for $myfoundpage has a field for pet_name, then $myfoundpage->pet_name will give you the pet's name.It you want to get really fancy, you can display entire multiple pages inside one master page, using the render method of a page (it comes with that $page that is built into eachPW page.) echo $pageA->render(); echo $pageB->render; echo $pageC->render; would display the contents of all three PW pages on the one browser page. Or you might set up a master/child type of page, where the contents of the bottom part of the page are changed through an ajax call depending on what actions are taken at the top of the page.You'll probably get the idea pretty quickly by getting in and having a go. I'd suggest using a really simple template and going through Ryan's mini tutorial on templates at the end of this post The tutorials section of the forum is a pretty good place to start as well. There's also the wiki 8 Link to comment Share on other sites More sharing options...
kongondo Posted January 20, 2014 Share Posted January 20, 2014 (edited) Hi Wilsea, Impressive summary of your initial take about the ins and outs of PW. Thanks. A few things need clarification: Pages - interesting further reading here by Joss It is important to understand the distinction between templates and template files. Templates do not have to have a template file with the same name as the template; you can tell PW you'll be using a different name. E.g. a Template called "Nit" can be associated with a Template File called "Picking". Template Files and not Templates display your data (in the fronted) Templates do not need to have a Template file Advanced template and template file approaches - classic thread by Soma and others. $page->first_name: in this case, there is a field on that page called first_name. If there isn't PW will complain very loudly Yes, fields are reusable. Some people get confused by this (not you). So, to further clarify, what it means is that you can add a field to as many different templates as you like and each of them (the field) will be a different instance of the field. It is important to add that removing fields from a template only removes the field's instance in that template and not in others. Also, you can't delete a field that is in use by any template. You can override the label of a field on a template by template basis (i.e. the instance of the field) For those who want to dig deeper: Each field (not each instance of the field) is actually a table in the PW database. The table will be named "field_field-name" (e.g. field_email). Each field instance is a row in that field's table Title field is not mandatory The only mandatory field in PW is Name. In the default install that ships with PW, Title is designated as a Global Field, hence required in all templates, hence its omnipresence. Hence, apart from name, in PW, all fields are custom fields. The name field is used to build the URL ...btw, the name and title of a page can be different Good job though! Cheers/k Edited January 20, 2014 by kongondo 5 Link to comment Share on other sites More sharing options...
wilsea Posted January 20, 2014 Share Posted January 20, 2014 Thanks for the comments kongongo. Joss's post on pages is a gem. I did a little bit of editing to try to make it clearer that it's the template files that control the display and not the templates. Thanks for pointing out that the template files didn't have to have the same name as the templates - bit of an aha moment there. One template for the viewed page, another for the page to be printed. Back to the API...$pages have a template property, and templates have a filename property (and lots of other properties too). That thread about advanced use of template starts to make more sense now. I recall reading in a post somewhere that PW is addictive. They were right. I'm hooked. 1 Link to comment Share on other sites More sharing options...
paulg Posted January 21, 2014 Author Share Posted January 21, 2014 Thank you all for your replies, that really does help with the learning and amazing amount of detail, Really appreciated Paul 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