mindplay.dk Posted November 9, 2012 Share Posted November 9, 2012 I built a basic "block" system, with reusable "blocks" you can add to sidebars, etc. - using just a couple of AsmSelect fields, and it's working great! No code was necessary, just a couple of fields and a few simple templates. One of those blocks is a menu-block, where the content manager can build a list of pages that should appear in a menu, which you can then add to any page. That's working fine too. Where I'm stuck, is I'm looping over my list of blocks and rendering them, like so: <?php foreach ($blocks as $index => $block): ?> <?= $block->render(); ?> <?php endforeach; ?> Very simple - I have different types of blocks that use different templates, and this works nicely. But I'm having a problem with the menu-block, which needs to know which Page is currently being viewed, so it can add an "active" class to the list-item. My menu-block template looks something like this: <ul class="menu-block-links"> <?php foreach ($page->pages as $item): ?> <li<?= wire('page')->id === $item->id ? ' class="active"' : '' ?>><a href="<?= $item->url ?>"><?= $item->title ?></a></li> <?php endforeach; ?> </ul> The problem here, is that wire('page') seems to get overwritten whenever you render() a Page? In other words, wire('page') gives me the menu-block, because that's what's currently being rendered - but what I need is the Page that was actually requested. Is there any way to get your hands on that, or is it lost as soon as you call render() on a Page?? Link to comment Share on other sites More sharing options...
WillyC Posted November 9, 2012 Share Posted November 9, 2012 you.try this <?php foreach ($blocks as $index => $block): ?> <?= $block->set('pagamos', $page)->render(); ?> <?php endforeach; ?> menu-black tamplate: <ul class="menu-block-links"> <?php foreach ($page->pages as $item): ?> <li<?= $page->pagamos->id === $item->id ? ' class="active"' : '' ?>><a href="<?= $item->url ?>"><?= $item->title ?></a></li> <?php endforeach; ?> </ul> 3 Link to comment Share on other sites More sharing options...
mindplay.dk Posted November 9, 2012 Author Share Posted November 9, 2012 You, Sir, have awesome facial hair! You also solved my problem, thanks! 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