Get block data from parent page?
Permalink
Hi, hoping someone can help,
I've got a set of child pages that have a block I built where they can choose multiple values from a checkbox list. Is it possible to get the values saved in the block on a page template if i know each child pages ID number. Not finding much in the documentation to show me how to load just the data of the block on a parent page i dont need the full block & view just the values each page has set in the block so that i can then use it to sort with.
Thanks.
I've got a set of child pages that have a block I built where they can choose multiple values from a checkbox list. Is it possible to get the values saved in the block on a page template if i know each child pages ID number. Not finding much in the documentation to show me how to load just the data of the block on a parent page i dont need the full block & view just the values each page has set in the block so that i can then use it to sort with.
Thanks.
hello,
I have 2 questions about what you're trying to do.
First, couldn't you use page attributes to do that? You're saying all you want that block for is to access a selected value. That's really what page attributes are meant to do. You add an attribute to a page, give it a value, and get the value from the page any tie you need it.
Second, if attributes won't work for you, can you say a little more about what's not working? What you're doing seems correct. What is it that you are getting or not getting?
I have 2 questions about what you're trying to do.
First, couldn't you use page attributes to do that? You're saying all you want that block for is to access a selected value. That's really what page attributes are meant to do. You add an attribute to a page, give it a value, and get the value from the page any tie you need it.
Second, if attributes won't work for you, can you say a little more about what's not working? What you're doing seems correct. What is it that you are getting or not getting?
Ended up doing it a different way and just getting the data straight from the database, probably not the best but worked for the information I had.
Block::getByID just kept returning blank for me.
$db = \Database::connection(); $blocksData = $db->fetchColumn('SELECT * FROM btBlockName WHERE bID = ?', [$blockID]);
Block::getByID just kept returning blank for me.
- child pages ID
- The block ID
- Value name saved in block on each page
I'm trying to use
$page = Page::getByID($childPageID);
$block = Block::getByID($bID, $page);
But not getting any results