cancel
Showing results for 
Search instead for 
Did you mean: 

How to include a new client side javascript dependency into form.get.html.ftl

douglascrp
World-Class Innovator
World-Class Innovator
Hello.

I'm trying to include a new dependency for form.get.html.ftl using a extension module.

My custom ftl file contains the following code:

<@markup id="group-member-form-control-dependencies" target="js" action="after" scope="global">
   <@script src="${url.context}/res/components/object-finder/group-member.js" group="form"/>
</@markup>

But it seems my code is ignored.

The extension module definition is:
<extension>
    <modules>
        <module>
            <id>Custom group member form control dependencies</id>
            <auto-deploy>true</auto-deploy>
            <customizations>
                <customization>
                    <targetPackageRoot>org.alfresco.components.form</targetPackageRoot>
                    <sourcePackageRoot>org.orderofthebee.components.form</sourcePackageRoot>
                </customization>
            </customizations>
        </module>
    </modules>
</extension>

What I ended up doing is including the dependency using share-config:


    <config>
        <forms>
            <dependencies>
                <js src="/components/object-finder/group-member.js" />
            </dependencies>
        </forms>
    </config>

2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Going the configuration way IS the proper way to include custom form dependencies. Depending on the use case, the the form.get.html.ftl may not be used to initialize a form context, e.g. some components include the form.js.ftl and form.css.ftl to get all the form dependencies. Customizing form.get.html.ftl will miss those use cases, but configuration will work fine.

The scope attribute for a @markup is not relevant / defined at all. Also a @script inside a @markup may behave differently than what you would expect, e.g. if the @markup has an action of "before" the script you include will still be loaded after any scripts from the element you targeted. Additionally, it is impossible to use the action of "replace" to remove any @script dependency, since those are always decoupled from the @markup that surrounds them (deferred template model).

douglascrp
World-Class Innovator
World-Class Innovator
Thank you Axel.