Joss Posted December 10, 2012 Share Posted December 10, 2012 Sorry, very quick and silly question. On a template, how do you call in a specific page and render it? I know you can call it by id <?php echo $pages->get(1036)->render(); ?> And I know you can get the children, But can you call it just by name? This is for the wiki. EDIT: And another question, is there a way of finding the page ID other than editing it? (And getting the ID from the address bar) Joss Link to comment Share on other sites More sharing options...
nik Posted December 10, 2012 Share Posted December 10, 2012 You can use the same selectors with get() than you'd use with find(). So for example getting a page called "footer" under page /blocks/ would be something like: $pages->get("parent=/blocks/, name=footer") When using get(), if the selector matches more than one page, only the first match will be returned. 1 Link to comment Share on other sites More sharing options...
Joss Posted December 10, 2012 Author Share Posted December 10, 2012 Thanks Nik, So does it require a relationship unless it is called by id? The bit in the WIki I am working out is all about calling in pages (and rendering them) into another page. http://wiki.processwire.com/index.php/Including_a_page_in_another_page (only part done) So for the moment I am covering: Calling in a single page and rendering it directly in a template file. Calling in a single page via a "Page field" and rendering it Calling in a series of child pages and rendering them directly in a template file Calling in a series of pages via a pages field and rendering them. I have 2 and 3 sorted, have not thought about 4 yet and am a little puzzled by 1. I am being careful to explain in which circumstances if you move a page, you mess up your system, and when it is okay, for instance calling by ID. 4 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 10, 2012 Share Posted December 10, 2012 So does it require a relationship unless it is called by id? By path: $singlePage = $pages->get("/blocks/footer/"); Link to comment Share on other sites More sharing options...
Joss Posted December 10, 2012 Author Share Posted December 10, 2012 Thanks Martijn Okay, so there is a relationship there. If it is moved from /blocks/ it will break. Which reinforces the point I am making that unless this is part of your template structure (for some reason) it is better to pull a page in via a Page Field so you are not messed up when it moves and you can change the source page easily. Ta much! (PS: Last time I met someone called Martijn, I wrote a whole pile of music for his fantastic animations for the Dutch government. Good money too!) 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 10, 2012 Share Posted December 10, 2012 Lot's of Martijns over here in Holland. People call me Tinus therefore. (ps: I like your writing&positive style here on the forum) Link to comment Share on other sites More sharing options...
diogo Posted December 10, 2012 Share Posted December 10, 2012 You can call only by the name, but there is the risk of matching more than one pages because you are allowed to give the same name to different pages if they're not under the same parent. Link to comment Share on other sites More sharing options...
apeisa Posted December 10, 2012 Share Posted December 10, 2012 Joss, there are many many ways to find Page / PageArrays. $pagesAboutAntti = $pages->find("title*=Antti"); // It does "break" only if title is changed $anttisChildren = $pages->get("name=antti-peisa")->children(); // It search for page which name is antti-peisa and returns all it's children $personCalledAntti = $pages->get("template=person, name=antti"); // This one I use a lot - combined with family settings it is pretty much bulletproof Btw: I myself almost never use the $somePage->render() - I have found very little use for it (for widgets/blocks maybe). So much more common case is to grab a page and output only what is needed, like this: $latestProduct = $pages->get("template=product, sort=-created"); echo "<a href='$latestProduct->url'>$latestProduct->title $latestProduct->price €</a>": Link to comment Share on other sites More sharing options...
Joss Posted December 10, 2012 Author Share Posted December 10, 2012 Diogo - That is a very good point! Thanks Apeisa - Yes, I have been using for blocks in boostrap templates, but I agree, it is better to be more focused and pull specific information in other uses. I suspect that the "Pages" section of the Wiki and any subsequent manual is liable to become the most complicated and thus, the hardest to understand. It really needs to be broken down into specifics - use this for this situation - so that users can make a really good judgement on which way to go. Perhaps it could do with a sort of Best Practices article that lists the methods without the fine details so you can browse through and say "that is the sort of thing I want to achieve" and follow the link through to the detail. You guys up to helping on that? Joss 2 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