Jump to content

Selector issue - retrieve sub-field value


Peter Knight
 Share

Recommended Posts

Hey I'm building my first new site in well over a year and am a little rusty on selectors but particularly retrieving sub-fields of selected pages.

I am trying to output the meta data of a blog post as follows.

Quote

Posted by [Person Name], [Job title].

[Person Name] is just a field with a Page Reference and simple enough.
[Job Title] is the sub-field within the page that was referenced above.

I actually have it working with the following:

Posted by:

<?php
	if($page->insight_author) {
	echo $page->insight_author("<a href='{url}'>{title}</a>");}
?>
,
<?php
	$roles = $page->insight_author;
	foreach ($roles as $role) {
	echo "{$role->staff_role}";} 
?>

but was wondering how to do this with selector sub-selectors instead. My current code is probably quite 'old school'?

Thanks

 

Link to comment
Share on other sites

Posted by:

<?php if($page->insight_author): ?>
	<a href='<?= $page->insight_author->url ?>'><?= $page->insight_author->title ?></a>
<?php endif ?>
,
<?php foreach ($page->insight_author->roles as $role): ?>
	<?= $role->staff_role ?>
<?php endforeach ?>

I would suggest something like the above, though there are certainly other templating styles. Like @monollonom said, I'm not exactly sure what role represents or how that is structured.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...