Is it possible to query the current entry or category element via a Craft 3 plugin/module?
In the 2.6 era, I would use a hook. The Craft 3 iteration of a hook looks something like this:
$currentElement;
Craft::$app->getView()->hook('someHook', function(array &$context) {
if (isset($context['entry'])) {
$currentElement = $context['entry'];
} else if (isset($context['category'])) {
$currentElement = $context['category'];
}
});
With an accompanying Twig snippet in the template:
{% hook 'someHook' %}
I'm wondering if there is a cleaner practice to accomplish the same goal? I find relying on Twig snippet reduces the flexibility of my plugin.
I've noticed the SEOMatic plugin is able to append entry specific data without any hooks in the template. I can't figure out how, but it gives me hope.