Tags and modules in marker-bundle
With version 0.4.0, my marker-bundle for Symfony now has modules and better support for using the tags added to posts.
Tags
Post tags can actually be used now. When creating a post via the console command, it will ask for relevant tags, it has done this since the beginning, but they couldn't really be used for much.
But now there is the TagRepository with the main method being getTags().
Calling it without any tag it will return an array of all tags and its posts. Eg. this controller snippet.
#[Route('/', name: 'app_index')]
public function index(
PostRepository $postRepository,
TagRepository $tagRepository,
): Response {
$templateData = [
'posts' => $postRepository->getPosts(5),
'tags' => $tagRepository->getTags(),
];
return $this->render('index/index.html.twig', $templateData);
}
This can be useful for generating links to tags, like you can see on the home page of this site.
On the other hand, calling it with a tag like getTags('enshitification'), it will return all posts for that tag.
#[Route('/tags/{tag}', name: 'marker_tags')]
public function tags(
string $tag,
TagRepository $tagRepository,
): Response {
$templateData = [
'posts' => $tagRepository->getTags($tag),
];
return $this->render('marker/tag/index.html.twig', $templateData);
}
This can be useful for showing all posts for a given tag, like you can see here for tags with enshitification.
Modules
It is now also possible to have markdown modules.
Run bin/console marker:create:module to create the folder and markdown file needed.
Let's say we have a footer module, it could be in storage/contents/modules/footer/content.md. Add some markdown content to the file, it will be empty by default.
In Twig it can then be used with the modules Twig function.
<div id="footer">
{{ module('footer') }}
</div>
Pretty neat, huh?
This is more or less the first real guide on using the marker-bundle, I the nearest future I will add full guide as README in the repository.
Find the bundle at codeberg.org/tomrummet/marker-bundle.
Or install it with composer with composer require tomrummet/marker-bundle.
Both this website and marker-bundle is completely human made, no AI, need to keep my brain alive by doing something.
// ASH