Juergen Posted November 7, 2023 Share Posted November 7, 2023 Hello @all, I am struggeling to add a Fieldtype/Inputfield specific JS and CSS file to the frontend. Just to be clear: I am talking about the frontend not the backend! From a module it is not a problem! In this case I can use a Hook on Page::render to add the files. $this->addHookAfter('Page::render', $this, 'addmyFiles'); On a Fieldtype/Inputfield this does not work. Even @ryan uses to add the JS and CSS files of his Comments Fieldtype/Inputfield by hand to the frontend. Maybe it is not possible at all, but I want to know if other users probably have found a solution to achieve this. Best regards Link to comment Share on other sites More sharing options...
bernhard Posted November 7, 2023 Share Posted November 7, 2023 Sure, everything is possible in PW. Have a look at RockFrontend: https://github.com/baumrock/RockFrontend/blob/607fadd11bf1314458504f743ca8223e5847e71d/RockFrontend.module.php#L214-L236 The only thing you need is an autoload module so that the hook is fired on every request. 1 Link to comment Share on other sites More sharing options...
Juergen Posted November 7, 2023 Author Share Posted November 7, 2023 Thank you @Bernhard But unfortunately this doesn't work in my case if you have a FieldtypeMulti (or probably a Fieldtype as well) and the corresponding input field, even if autoload is set to true. When I add the ready() method, it doesn't take it into account - only the init() method. Maybe there is a difference between an ordinary module and a module of type Fieldtype. Maybe that could be the reason why Ryan didn't add the files via hook in his comment module either. Link to comment Share on other sites More sharing options...
bernhard Posted November 7, 2023 Share Posted November 7, 2023 A Fieldtype module is not an autoload module. Fieldtype/Inputfield modules are only loaded if needed and that's not the case on the frontend. Just create a master module that is autoload that adds those hooks and installs the fieldtype/inputfield modules for you. 1 Link to comment Share on other sites More sharing options...
Juergen Posted November 7, 2023 Author Share Posted November 7, 2023 Ok, I see ?! 17 minutes ago, bernhard said: Just create a master module that is autoload that adds those hooks and installs the fieldtype/inputfield modules for you. I'll think about it to see if it's worth the effort in this case. Link to comment Share on other sites More sharing options...
bernhard Posted November 7, 2023 Share Posted November 7, 2023 Or add RockFrontend as a dependency and do $rockfrontend->styles()->add(...) ? ? Link to comment Share on other sites More sharing options...
Juergen Posted November 7, 2023 Author Share Posted November 7, 2023 13 minutes ago, bernhard said: Or add RockFrontend as a dependency and do $rockfrontend->styles()->add(...) ? ? You are a real marketing man ??!! 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now