Mike
Mike

Reputation: 383

How to add new JS libraries in Alfresco Share Controls?

I am trying to develop new custom control template using select2 library. To accomplish that I have to include CSS and JS files . How can I achieve that?

I know I could manually add those files in the tomcat folder but I am on Docker so I do not have access to it.

Obviously I tried i include them inside <head> tag in .ftl file but it does not work.

Here is my customcontrol.ftl:

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>

<select class="courntyselect">
  <option></option>
  <option value="1">USA</option>
  <option value="2">France</option>
  <option value="3">Tunisia</option> 
  <option value="4">Canada</option> 
</select>

<script type="text/javascript">
$(".courntyselect").select2({
  width: "250",
  placeholder: "Select your country",
}).on("change",function(e){
  alert('Selected value : ' + e.target.value);
});
</script>

Upvotes: 1

Views: 336

Answers (1)

Sanjay
Sanjay

Reputation: 2493

You need to add those files in share-config-custom.xml as dependency.

<config>
        <forms>
            <dependencies>
                <js src="/js/datatable-datasource-min.js" />
            </dependencies>
        </forms>
    </config>

Place js file inside src\main\amp\web\js of share folder.

Upvotes: 2

Related Questions