What is the recommended way to register a Javascript to be loaded on the edit view (Archetypes) of certain content types?
Any examples of existing implementations?
Make sure your JavaScript code works OK in those content type edit forms and doesn't break on other situations (jQuery is your friend). Then add it to portal_javascripts.
If you can associate the JavaScript to certain widgets, add it as helper_js
for those widgets. Be careful with JavaScript as browser resources because I had trouble with '++resoure++'-like
URLs as helper_js
: apparently Archetypes doesn't like the plus (+) sign (doesn't escape plus sign correctly if I understand it OK).
You can define a page template named archetypes_custom_js
with a macro called javascript_head
and it will automatically be loaded in edit form of all Archetypes. You can then check special conditions in that macro. See base_edit.cpt
line 47.
To be honest is such cases I like the approach that use old fill-slot directly in the edit form of the type. The edit form is often not-so-frequently called (and for sure not from anonymous) so a little overhead due to downloading not-fully cached code is not so bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With