My problem with structured content is that I cannot get access into the structure. When I try to find a page that has been selected via structured content in the panel, “find” doesn’t work… Know what I mean?
As you can see I am creating a list of pages in the panel where the user can select which other pages he want to link to. Some kind of internal links. However, the links should include data from their origin i. e. the origin’s title, image, url, etc.
When I try to go inside the selected item via <?php echo $page->find( $advocat['selection'] )->url) ?> i keep getting errors like “Call to a member function title() on a non-object”.
I’ve tried multiple setups but the one above seems to be the one that should work - But doesn’t. I’m really stuck here, maybe you guys can help
$page->find() only finds subpages of the current page; $pages->find() will only find pages on the first level;
You need to use $site->index()->findBy('uid', $advocat['selection']) if the related page can be anywhere.
So this really depends on where your related pages are located …
Edit: I changed the code above, because find() does not seem to work with index(). Also, using the index might be a bit too much of a good thing if you have many pages, so it might be a good idea to narrow the selection down?
Thanks for your reply, always appreciated Yeah, narrowing down the selection would definitely be better but at the moment I just want this thing to work, hehe.
Haven’t tried index() before, but I can see your point. So i changed the code to…
… But this causes an “Invalid argument supplied for foreach()”. A warning instead of an error though I know that I want to do is totally solvable but as said: #brettvormkopf
The yaml structure is located in “lorem”. Here the panel user selects a page, like “ipsum”, which is somewhere else in the site. I want to get data from “ipsum” to be shown in “lorem”
Thank you so much! Me and a good pal were trying toStructure() as well but we didn’t connect that with (string)$string. Phew, I feel really relieved now. Thanks again