Specifying a tag to sort by for an individual page

Hi, I’m working on pulling in headlines and content from any page in my site based on a specific tag, that needs to change for each instance of the template.

Right now my php for this looks like:

<?php foreach($site->index()->filterBy('template', 'composition')->filterBy('tags', 'apparitions', ',')->flip() as $article): ?>

Which should then allow me to pull data from all my composition templates that are tagged “apparitions” - this works great, but, now I’d like to dynamically specify what tag is used to pull content. I attempted the following:

<?php foreach($site->index()->filterBy('template', 'composition')->filterBy('tags', '<?php echo $page->pulltag() ?>', ',')->flip() as $article): ?>

and added a pulltag element to my blueprint and /txt file but it’s not functioning (it’s just showing up empty)

Is there a better way I can be doing this? I’d rather not have to make a new template for each page, as that sort of defeats the purpose.

Right now the non-functioning code is plugged into this page: http://data.randy-gibson.com/projects/apparitions and the functioning to: http://data.randy-gibson.com/projects/apparitions_working


This should work:

<?php foreach($site->index()->filterBy('template', 'composition')->filterBy('tags', $page->pulltag(), ',')->flip() as $article): ?>

Ah! Success! Thank you so much! It seems that it is caps sensitive, but it’s working. Amazing.

Explanation: You used quotation marks around your PHP code, so that it was not executed but regarded as a string. Also, it is not useful to use PHP tags inside of PHP code.

That all makes sense. Have been trying to wrap my head around the particulars of PHP, this is super helpful.

Thanks again