Fórum

How to include custom javascript in freemarker template in DXP theme

thumbnail
Narsingh Pal, modificado 7 Anos atrás.

How to include custom javascript in freemarker template in DXP theme

Junior Member Postagens: 53 Data de Entrada: 18/01/14 Postagens Recentes
Dear all,

Wanted to know how can we include custom javascript files in the freemarker template "portal_normal.ftl" in DXP theme.

FYI. The location of my javascript file in theme is "src/js/myJs.min.js"

I tried following ways, but no luck
1. <@liferay.js file_name="myJs.min.js"/>
I get below error on browser console
"http://localhost:8080/myJs.min.js Failed to load resource: the server responded with a status of 404 (Not Found)"

2. <script src="${javascript_folder}/myJs.min.js"/>
I don't get any error, but the page goes blank. When I see the page source I can find the following thing computed
<script src="http://localhost:8080/o/my-theme/js/myJs.min.js"/>
Also, I am able to find the javascript, at above location, but the page displays nothing.


Thanks and Regards
Narsingh Pal
thumbnail
Narsingh Pal, modificado 7 Anos atrás.

RE: How to include custom javascript in freemarker template in DXP theme

Junior Member Postagens: 53 Data de Entrada: 18/01/14 Postagens Recentes
Dear Friends,

Any suggestions ?


Thanks and Regards
Narsingh Pal
thumbnail
Onno van der Zee, modificado 7 Anos atrás.

RE: How to include custom javascript in freemarker template in DXP theme

New Member Postagens: 2 Data de Entrada: 11/03/15 Postagens Recentes
example for libraries:
<script type="text/javascript" src="${javascript_folder}/jquery-1.11.2.min.js"></script>
example for your own scripts:
<#assign common_js_file = htmlUtil.escape(portalUtil.getStaticResourceURL(request, "${javascript_folder}/common.js")) />
<script src="${common_js_file}"/></script>

maybe you have to check your files are in ${javascript_folder}

emoticon
thumbnail
Narsingh Pal, modificado 7 Anos atrás.

RE: How to include custom javascript in freemarker template in DXP theme (Resposta)

Junior Member Postagens: 53 Data de Entrada: 18/01/14 Postagens Recentes
Narsingh Pal:

<@liferay.js file_name="${javascript_folder}/myJs.min.js"/>

I recently upgraded to Liferay 7 GA3 and this seems to work in GA3.
Ashwini Sidhanti, modificado 4 Anos atrás.

RE: How to include custom javascript in freemarker template in DXP theme

New Member Postagens: 3 Data de Entrada: 22/12/16 Postagens Recentes
<@liferay.js file_name="${themeDisplay.getPathThemeJavaScript()}/showMeer.js"/> 
This worked for Liferay 7