Jump to content

echo $page in page with template?


Gerge.ly
 Share

Recommended Posts

Hi,

I'd like to build a dynamic page, where I can define rows and coloumns, with bootstrap.

I have implemented bootstrap and everything is working fine, I'm just a bit confused how to output a page inside a page.

The reason I want to do this is because you can't have repeaters inside repeaters as I have read. So I thought i do it this way:

homePage

-- homePageContent

-- -- row-divs

-- -- row-slider

-- -- row-etc

For example, the row-divs is a template with a repeater, made out of a Fieldset with Title + Text.

the row-divs is a template, where I loop through the repeater, dynamicly calculating the "col-md-x" size and limiting the divs per row.

Now my problem is, that I want to output the whole page with the template "row-divs" in homePage.

Pseudocode:

$subPages = $page->children('title=homePageContent")->first;
foreach($subPages as $subPage):
 echo $subPage;
endforeach;

This should output  row-divs, etc the way it would be outputted as single page, like:

<row>

-- <div 1>

-- <div 2>

</row>

<row>

-- <div 1>

-- <div 2>

-- <div 3>

</row>

if e.g. there are 2 pages in homePageContent with row-divs template, one with 2 divs and one with 3 divs.

I know I could achieve this by outputtung the fields of the children by hand, but I pretty sure processwire is able to output a page in a page formatted with its template, but I couldn't find it in the docs...

Thanks

Edited by Gmen
Link to comment
Share on other sites

Hi,

thanks for your reply! This is what I have been looking for!

I saw PageTable, but it isn't exactly what I need. The Use-case for col-divs is just one. This way I could have a template row-sliders and assign row-sliders children with the actual slides. Those slides actually need to be pages.

Link to comment
Share on other sites

An alternative that I just implemented:

I set up field 'bootstrap_column' as a Repeater, with fields 'bootsrap_column_span' and 'body'. 'bootstrap_column_span' is an integer field with value range 1-12.

Then I loop through the bootstrap_column field and keep track of the column spans, creating new rows as necessary:

echo '<div class="row">';

$i = 0;

foreach ( $page->bootstrap_column as $column )
{
	$i += $column->bootstrap_column_span;

	# if: over 12 columns; start a new row
	if ( $i > 12 )
	{
		$i = $column->bootstrap_column_span;

		echo '</div> <!--/.row -->';

		echo '<div class="row">';
	} # end if

	echo sprintf('<div class="span%d"> %s </div>',
		$column->bootstrap_column_span,
		$column->body
	);
} # end loop

echo '</div> <!--/.row -->'; 

It may not be the most efficient method and the repeater field doesn't reflect how it will look on the front end, but I think it will work for my needs so far. I actually didn't look into PageTable or setting up sub-pages for different sections of content.

Edit: just realized I missed the conditions when the column span is exactly 12. I will need to add that. :)

Link to comment
Share on other sites

Hi,

this is exactly the way how my template "row-divs" works, but it also spreads the divs evenly across the row (2divs; col-md-6) or with specified col-size.

Of course I could add this to homePage, (parent page) but this would come with 2 limitations I don't want:

1) you can't move/order the row/rows on the page, (this way it can be moved on admin backend, because they are pages :) )

2) I have different row-templates, one example is the slider, also with children, which are required to be presented as single pages

the render() function works very wel, thanks.

Thanks for all the replies. I'm just moving from Wordpress to ProcessWire and it is a dream!

Edited by Gmen
  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...