Jump to content

Recommended Posts

Posted

Sorry, I am full of questions at the moment.

But it is my birthday and I have been spending the day avoiding clients a messing around!

I want to render a row of pages (as blocks) in my bootstrap template. The idea is that you can create these special pages and it will display the most recent three in a row - the whole rendered page in each case.

So I think I want to do something like:

$footers = $pages->get("/home/blocks/footer-blocks")->children();

foreach($footers as $footerblocks) {

echo $footerblocks->render();

}

Then do a limit=3 somewhere.

I am sure I read something somewhere that had at least part of the answer, but I cannot find it!

Am I heading the right direction?

Joss

Posted
$footers = $pages->get("/home/blocks/footer-blocks")->children('limit=3');

I know right, too easy. :P That all you need for the limit at least.

Generally the rest sounds doable, ProcessWire won't dictate the method so it's up to you really.

Posted

Certainly heading in the right direction. I would try

$footers = $pages->get("/home/blocks/footer-blocks/")->children("limit=3");

(Completely untested - I'm sure someone will correct me.)

<edit>adamspruijt beat me to it</edit>

Posted

Ah, replies in harmony!

I approve.

You have to remember that all the so-called coding I do is cutting and pasting little bits from everywhere and guessing whether I have done the right thing.

So, I tend to err on the side of ... "Oh, that will never work!" with most things I do

Generally the rest sounds doable, ProcessWire won't dictate the method so it's up to you really.

I keep holding out for the system where I can literally write in my page

"Look, I sort of want to do this, lay it out a bit like this, and then control it by pressing a big blue button."

And the system will go - "What, like this?"

And voila, it works!

Joss

Posted

I keep holding out for the system where I can literally write in my page

"Look, I sort of want to do this, lay it out a bit like this, and then control it by pressing a big blue button."

And the system will go - "What, like this?"

And voila, it works!

PW is about as close as you'll find, for now.

(And I did have an extra '/' in my answer ^-^ )

Posted

Okay,

Part way there - the render() bit isn't working.

If I put $footerblocks->body; - then it outputs the body field, so the idea is right, just not quite doing what I hoped.

I will continue digging.

Joss

Posted

I believe render is meant to be used on an array:

$footers = $pages->get("/home/blocks/footer-blocks/")->children("limit=3");
$footers->render();

I'm not certain though, never really used it.

Posted

Happy birthday Joss. You'd want to render each individual page

$items = $pages->get('/home/blocks/footer-blocks/')->children('start=0, limit=3'); 
foreach($items as $item) {
 echo $item->render(); 
}

I added that "start=0" into the selector, just in case you are using pagination somewhere on the page. Otherwise, that isn't necessary.

Posted

Hi Ryan, thanks - going out for a serious Thai later. Take a break from cooking (http://www.foodloversdiary.com)

Yes, that is what I have been doing:

<?php $footers = $pages->get('/home/blocks/footer-blocks/')->children('start=0, limit=3');
foreach($footers as $footerblocks) { ?>
<div class="span3">
<?php echo $footerblocks->render(); ?>
</div>
<?php } ?>

Which is outputting nothing.

However, the following works with a specific field:

<?php $footers = $pages->get('/home/blocks/footer-blocks/')->children('start=0, limit=3');
foreach($footers as $footerblocks) { ?>
<div class="span3">
<?php echo $footerblocks->body; ?>
</div>
<?php } ?>

So, I am a bit confused.

Posted

render() renders the template of the page, do the children of footer-blocks have a working template?

edit: and happy birthday!!

Posted

I just checked their template. It is not very busy at the moment!

<div>
<?php echo $page->body; ?>
</div>

But seems to be all there.

Posted

GOT IT!

Anyone notice I had a superfluous "home" in the first line???

Removed that and it works. So my final code is:

<?php $footers = $pages->get("/blocks/footer-blocks/")->children("limit=3");
foreach($footers as $footerblocks) { ?>
  <div class="span3">
      <?php echo $footerblocks->render(); ?>
  </div>
<?php } ?>

Thanks everyone!

  • Like 2
Posted

render() renders the template of the page, do the children of footer-blocks have a working template?

edit: and happy birthday!!

WOW, ok so I was wrong, and that... is awesome.

Posted

The result, which is directly aimed at Bootstrap, means that I can line up blocks in a row and the client can change them just by re-ordering the pages. I might add a count so that if there are 3, the class is Span4, if there are 2 it is span6, if 4, span3 and so on. Might be fun ..... or confusing!

Joss

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
  • Recently Browsing   0 members

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