brandy Posted October 19, 2020 Share Posted October 19, 2020 Hi! I´m building my first website with Processwire, after changing from some other CMS. As the title says, it´s for a real estate company, which has several projects. I made a home-template, a project-template and one template for the apartments with a working menu. The site-structur is this one: Home --> Project --> Apartment --> Apartment 1 --> Apartment 2 --> Apartment 3 --> Apartment 4 --> ... Now, I want to have the projects shown on the homepage. One project should be the "main"-project. To do so, I need the data from the several subpages. How do I get the information to the top or to another location? My customer should be able to choose which project should be on top! Thanks a lot! Link to comment Share on other sites More sharing options...
psy Posted October 19, 2020 Share Posted October 19, 2020 Hi Brandy and welcome to ProcessWire There are many ways to achieve what you want. Hardest part is deciding which method works best for you and you client, eg: On your home page template you could have a Page reference field that allows your client to choose the featured projects and make the first the "main" project. For output, loop through the chosen page references and ensure the main project (page reference Project #1), gets different, more prominent styling. Use Tags on Project pages, eg "Home page featured" & "Home page other". Then in your home page template, use a selector to get the featured projects and loop through as above Based on info you supplied, I'd go with option 1 Hope this helps Link to comment Share on other sites More sharing options...
brandy Posted October 19, 2020 Author Share Posted October 19, 2020 Ok, very cool - thanks a lot! And how does it work, if I only want to have only some of the fields of the subpage? Do I need a new template? Thanks a lot! Link to comment Share on other sites More sharing options...
dab Posted October 19, 2020 Share Posted October 19, 2020 Have a look at delayed output strategy. You have one main "template"(_main.php) & can then simply create a new template for a sub-section page where you just add code for regions/sections of your _main template where you want to show different content (summaries, other content etc.). I found the intermediate templates a good starting point to see how _main.php & e.g. home.php or basic.php interact. Once you've learnt this, look at markup regions - super powerful (once mastered)! Link to comment Share on other sites More sharing options...
psy Posted October 19, 2020 Share Posted October 19, 2020 Those subpages are now linked to your home page and you change your home page template to show what fields you want. For example, if your page reference field is called 'featured', in your home page template you can choose what fields you need to show from the subpage. <?php foreach ($page->featured as $apartment) : if ($page->featured->first->id == $apartment->id) : // it's the first one ?> <div class='featured first'> <h2><?=$apartment->title?></h2> <p>Bedrooms: <?=$apartment->bedrooms?></p> <p>Bathrooms: <?=$apartment->bathrooms?></p> <p>Price: <?=$apartment->price?></p> </div> <?php else: // it's not the first one ?> <div class='featured'> <h3><?=$apartment->title?></h3> <p>Bedrooms: <?=$apartment->bedrooms?></p> <p>Bathrooms: <?=$apartment->bathrooms?></p> <p>Price: <?=$apartment->price?></p> </div> <?php endif; endforeach; ?> 2 Link to comment Share on other sites More sharing options...
brandy Posted October 20, 2020 Author Share Posted October 20, 2020 Hi again! Thanks a lot for your help. Now I have a very basic question: I have numerous fields for every detail of the project (size, rooms, etc.). Now I want to show the different fields on the site. The image is shown via: <?php if($page->site_main_image) echo "<img src='{$page->site_main_image->url}' alt='$image->description' />"; ?> How do I show a field? I tried with: <?php if($page->project_app_floor) echo "<td>{$pages->get("project_app_floor")}</td><td>{$pages->get("project_app_floor")}</td>"; ?> I don't really know, if I have to refer to the field directly or if I need the page. Thanks a lot! Link to comment Share on other sites More sharing options...
kongondo Posted October 20, 2020 Share Posted October 20, 2020 Welcome to the forums and to ProcessWire @brandy :-). 39 minutes ago, brandy said: Now I have a very basic question: 40 minutes ago, brandy said: I don't really know, if I have to refer to the field directly or if I need the page. I don't know how much of the docs and/or tutorials you have gone through already. If you haven't already seen the docs about $page and $pages. I'll also throw in selectors. You'll get along better and farther with these under your belt. 1 Link to comment Share on other sites More sharing options...
brandy Posted October 20, 2020 Author Share Posted October 20, 2020 Yeah, I have been going throug many pages, but I don´t understand how I get down to a field. I mean getting the properties of a page, like the image in the example above is clear and I do understand. But I´m not able to move it to a field. The direct way {$page->FIELDNAME->label} doesn´t work. So I tried a different way $fields->get("FIELDNAME") I guess you guys are laughing your heads off :-) I´m totally confused at what end I am, and where to look for the field and its content... Link to comment Share on other sites More sharing options...
rick Posted October 20, 2020 Share Posted October 20, 2020 Hi @brandy and welcome to the forum. First, no one laughs. Second, take a look at this older post. Lastly, just an FYI, you can better search the forum content by typing this into your browser: site:processwire.com/talk {search terms} or you can use /blog rather than /talk to search the blog articles. You'll find that everyone here is both knowledgeable and willing to help, so please ask away! Link to comment Share on other sites More sharing options...
kongondo Posted October 20, 2020 Share Posted October 20, 2020 (edited) 20 minutes ago, brandy said: I guess you guys are laughing your heads off :-) Definitely not! That's not how we roll in this community. 20 minutes ago, brandy said: I´m totally confused at what end I am, and where to look for the field and its content... I guess you should start here then? https://processwire.com/docs/start/templates/ 20 minutes ago, brandy said: Yeah, I have been going throug many pages, but I don´t understand how I get down to a field. I mean getting the properties of a page, like the image in the example above is clear and I do understand. It's always the name of the field :-) <?php namespace ProcessWire; // will yield its value // @note: the value can be as simple as a string or integer, or more complex, e.g. an array or object // @note: that field must be present in the template that this page uses $page->name_of_field; In other words the 'name of the field' is a property (some would say attribute) of that page. Just like things (humans, buildings, animals, etc) have properties/attributes: height, width, etc. Edit Also note that $page always refers to the current page, but the principle of 'name_of_field' still applies. For example: <?php namespace ProcessWire; // this page we are viewing // get a property from it. $height = $page->height;// height is the name of an integer field in the template used by this page echo $height; // get another page not currently in view // get it using its ID $anotherPage = $pages->get(1234); // this other page uses the same template as our 'current page' above // so, we can get its height property as well $anotherPageHeight = $anotherPage->height; echo $anotherPageHeight; // @note: we only echo 'simple' field values, i.e. those that do not return an array or an object, etc Edited October 20, 2020 by kongondo 1 Link to comment Share on other sites More sharing options...
brandy Posted October 20, 2020 Author Share Posted October 20, 2020 Man, it´s always easier as it looks like... Thanks a lot - I have to see it from the page´s angle. Thanks a lot! It works now... If I´m ready I will show you my work. 1 Link to comment Share on other sites More sharing options...
kongondo Posted October 20, 2020 Share Posted October 20, 2020 23 minutes ago, brandy said: If I´m ready I will show you my work. Looking forward to this! ? Link to comment Share on other sites More sharing options...
brandy Posted November 9, 2020 Author Share Posted November 9, 2020 On 10/19/2020 at 10:18 PM, psy said: Those subpages are now linked to your home page and you change your home page template to show what fields you want. For example, if your page reference field is called 'featured', in your home page template you can choose what fields you need to show from the subpage. <?php foreach ($page->featured as $apartment) : if ($page->featured->first->id == $apartment->id) : // it's the first one ?> <div class='featured first'> <h2><?=$apartment->title?></h2> <p>Bedrooms: <?=$apartment->bedrooms?></p> <p>Bathrooms: <?=$apartment->bathrooms?></p> <p>Price: <?=$apartment->price?></p> </div> <?php else: // it's not the first one ?> <div class='featured'> <h3><?=$apartment->title?></h3> <p>Bedrooms: <?=$apartment->bedrooms?></p> <p>Bathrooms: <?=$apartment->bathrooms?></p> <p>Price: <?=$apartment->price?></p> </div> <?php endif; endforeach; ?> @psy: How do I filter out only some fields from the page, linked via the page reference field? Can I use the fields from the referenced page in the template of the current site? Link to comment Share on other sites More sharing options...
brandy Posted November 17, 2020 Author Share Posted November 17, 2020 Ok, I already found it - thanks a lot! It´s easier than I thought! 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