fisharebest / webtrees

Online genealogy
https://webtrees.net
GNU General Public License v3.0
419 stars 290 forks source link

Add CSS/JS content only to specific sites containing a custom module #4908

Open magicsunday opened 7 months ago

magicsunday commented 7 months ago

It is currently possible to write content in the page header or footer via the “ModuleGlobalInterface” interface. The disadvantage here is that this happens on every page. How can I ensure that my module CSS files are only written in the page header, on the pages on which the module is located (normal plugin page as well as in the chart block)? Is this already possible?

This is not a problem on the normal plugin side, but if the module is integrated on the tree homepage as a chart block (possible if you deactivate the default pedigree chart so that the custom module is used), then the CSS files appear in the middle of the tag. If you integrate a chart module multiple times on the homepage, the CSS files will also be integrated multiple times, which is not helpful. You could now get the CSS files into the header via ModuleGlobalInterface, but these would then also be integrated into all other pages where my module is not located.

The main problem I think is that each block is rendered separately and also creates a separate View instance without having knowledge of the actual parent View. I think you could get around this if there was actually only one view instance per page rendering.