Jump to content

Is it possible to add Javascript and/or CSS to a template from a Fieldtype/Inputfield


Juergen
 Share

Recommended Posts

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

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

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...