Tom. Posted July 19, 2016 Share Posted July 19, 2016 I'm rendering out a foreach based on a Repeater field, however I'm using it for link blocks and I don't want it to display if the block links to the current page. Using $item->link != $page doesn't work because $page returns the page the repeater is on, not the page we are currently viewing. EDIT: Explained 'betterer' Sorry when I say render out a foreach, I quite literally mean $page->render("repeater_block"); inside /fields/repeater_block.php using $page will return the page the repeater is on. So doing $page->get(1023)->render("repeater_block"); means I can't access the current page inside the repeater. Even when using $page. Link to comment Share on other sites More sharing options...
tpr Posted July 19, 2016 Share Posted July 19, 2016 Do they? Aren't you overriding $page somewhere in your code? 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 19, 2016 Share Posted July 19, 2016 If you find $page to not return the correct page (overwritten somewhere or whatever else) just use wire('page') or $this->wire('page') (depending on the context) instead. Link to comment Share on other sites More sharing options...
Macrura Posted July 19, 2016 Share Posted July 19, 2016 don't you need to use $item->getForPage() (should return the page the $item is assigned to) <?> at least that's how i always deal with repeaters if they are not in $page context Link to comment Share on other sites More sharing options...
Tom. Posted July 20, 2016 Author Share Posted July 20, 2016 7 hours ago, tpr said: Do they? Aren't you overriding $page somewhere in your code? 7 hours ago, LostKobrakai said: If you find $page to not return the correct page (overwritten somewhere or whatever else) just use wire('page') or $this->wire('page') (depending on the context) instead. Sorry when I say render out a foreach, I quite literally mean $page->render("repeater_block"); inside /fields/repeater_block.php using $page will return the page the repeater is on. So doing $page->get(1023)->render("repeater_block"); means I can't access the current page inside the repeater. Even when using $page. 7 hours ago, Macrura said: don't you need to use $item->getForPage() (should return the page the $item is assigned to) <?> at least that's how i always deal with repeaters if they are not in $page context Thanks for your input, I've explained more above - @Macrura @LostKobrakai @tpr Link to comment Share on other sites More sharing options...
Tom. Posted July 22, 2016 Author Share Posted July 22, 2016 Shameless bump Link to comment Share on other sites More sharing options...
Soma Posted July 22, 2016 Share Posted July 22, 2016 You use wire("page") If rendering a repeater field from another page, let's say echo $pages->get(1001)->render("repeater_field"); So in template/fields/repeater_field.php echo "<p>Page containing the repeater: " . $page->title . " " . $page->id . "</p>"; echo "<p>Page currently requested: " . wire("page")->title . " " . wire("page")->id . "</p>"; // render each repeater echo $value->each("<section><h2>{title}</h2>{body}</section>"); 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