Jump to content

include a page in an array


Atlasfreeman
 Share

Recommended Posts

Hi!
I want to make a small site, a one page site.
And i have this idea about doing 2 to 3 diffrent template that i can load into the index / home page.

I want to do this with an array so that i can keep creating more topics (with the template) id needed.

<?php include('./head.inc'); // include header markup ?>

<?php
$children = $page->get('template=onecolmn|twocolumn, sort=sort');
foreach($children as $child) {

include($child);

}
?>

<?php include('./foot.inc'); // include footer markup ?>

 

As you can see i have to template wish i want to control from the backend.
I know include does not work this way, put what is my other option to make an array that loads the whole page on an other pages.
 

 

Link to comment
Share on other sites

6 hours ago, Atlasfreeman said:

$children = $page->get('template=onecolmn|twocolumn, sort=sort');

You may want to revise this line. 'get' will return only the first match. To return a page array, you need $pages as well. Try:

<?php
$children = $pages->find('template=onecolumn|twocolumn, sort=sort');

 

  • Like 3
Link to comment
Share on other sites

$children = $pages->find('template=onecolumn|twocolumn, sort=sort');
foreach($children as $child) {
echo $child->render;

}

So i tried this..

But now i just says (on the page) Render page Rander page. So it does render it two times (it only should find 2 pages)
So that's good something happening. but it does not render the code i want.
Do "render work with the "pages" (more that one) array?

Link to comment
Share on other sites

On 10/9/2019 at 11:22 PM, psy said:

template=onecolumn|twocolumn

@Atlasfreeman Do you actually have template files for those templates?

How complex are those pages? Maybe you can just as well output the fields of those pages instead of using render().

Some more infos and options:

https://processwire.com/talk/topic/13958-help-understanding-render-and-rendervalue/

https://processwire.com/talk/topic/12228-render-options-documentation/

 

  • Like 1
Link to comment
Share on other sites

Super so yeah now it works!
So thank you all, For your great help!
This is really nice for building one scroll pages.
Then you could use diffrent template to create diffrent variations, when scrolling down.

Here is the working code for those finding this in the future!

					$children = $pages->find('template=onecolumn|twocolumn, sort=sort');
					foreach($children as $child) {
					echo $child->render();

 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...