I would like to create a plugin to load a specified template style for each article on Joomla 4. The basic idea is as follows:
Use a custom field in the article to specify the desired template style on a per-article basis.
Create a plugin so that whenever the article is loaded it is diplayed with its template, as specified in the custom field.
Based on this post I understand that I need to create a system plugin for the onAfterInitialise event.
Now I have a couple of questions regarding how to implement this in practice.
According to my understanding, the document itself is not loaded by the time the onAfterInitialise event is fired, which means that I would not be able to get the custom field's value directly at this point.
I should be able to get the article id from the the input object. Would it be feasible to do a database query to get the required template name, and then to set it also in the input object?
Perhaps I am missing the boat completely and I need to use a different approach. The main point is that I would like to specify a template style for each article and to load the article with that template style - without having to create menu items for each article (of which there are many). Most of the articles will be accessed without menu items, so creating such menu items and using them to specify the template style is unnecessarily cumbersome.
Thanks in advance for your assistance.