Snippets and specific page variables

“Variables” might be a tad misleading but I was not sure how to phrase it.

I’ve got a snippet called get_team.php which is fetching information and images for each specific team member. And then I use that in my templates like you normally would: <?php snippet('get_team') ?>.

The contents is very straight forward:
<?php foreach(page('team')->children()->visible() as $member): ?>
...
<?php endforeach ?>

In it I would also like to get the team page title and description (as defined in the blueprint). Pretty much in the same way such as this: <?php echo $page->title()->html() ?> but that will not work since I obviously is not using a specific blueprint and it’s corresponding template file here.

So, in a nutshell, this is what I’m trying to do:
<h1>Team page title</h1>
<p>Team page description</p>
...
[my foreach loop here]

Hopefully this all makes sense.

Maybe something like this (untested)?!


<?php $page_team = page('team'); ?>  
<h1><?php echo $page_team->title()->html() ?></h1>  
<?php echo $page_team->description()->kt() ?>  
<?php foreach($page_team->children()->visible() as $member): ?>  
...  
<?php endforeach; ?>

[EDIT] Does anybody know why my code example is displayed in single row?

1 Like

Yes, it works perfectly. Pretty obvious now that I see it but I guess I’ve been staring for this way too long. :wink:

OT: Do you have blank Lines before and after the code block? I think omitting them causes that the origibal breaks get lost …

Yes, there are blank lines. Changing the language from php to html seems to works. Thanks anyway :smile: