I am building a blog site. Each blog post has links to other recommended internal blog posts. There are also links to internal blog posts when readers do a search for a term, select a tag, or go to the archives page. I want all of these blog post links to be identical, and they each include title, date, tags, and image specific to the post they link to.
So I made a single snippet I was hoping to apply to each of the locations a link like this might appear. It won’t call anything though. The only way it works if if the php wrapper is present in the actual snippet. For example:
<!-- THIS IS THE PHP WRAPPER START, FOR CALLING TAG RESULTS -->
<?php foreach($site->page('blog')
->children()
->visible()
->filterBy('tags', param('tag'), ',')
->flip() as $result): ?>
<!-- THIS IS THE SNIPPET CONTENT (simplified to just call title for demonstration purposes here) -->
<p>
<a href="<?php echo $result->url() ?>">
<?php echo $result->title()->html() ?>
</a>
</p>
<!-- THIS IS THE PHP WRAPPER START
<?php endforeach ?>
This defeats the point of having a snippet, since the php wrapper is different for each page/location the link (snippet content) would need to appear, so I’d need to have that many individual snippets. I want one piece of code to keep track of these links to internal blog posts, since I want them to be identical everywhere.
Hope this is making sense! I have tried lots of things, I suspect it may be something to do with the concept of “passing variables to snippets” (https://getkirby.com/docs/templates/snippets) but I haven’t figured out how to make that work. I could be doing something wrong. Thanks in advance so so so very much for any and all help!