0

I'm developing a liferay 7.1 theme, based on bootstrap, using the theme generator.

With regard to JS, I have a directory /src/js/plugins containing several .js files, each corresponding to a different component (dropdown.js, list.js, ...).

Now, from the Liferay documentation, I saw that the javascript custom code should be inserted in the main.js file.

So, I ask you, how do I put all javascript files in the theme? What is the correct procedure?

PS. Building the bootstrap theme, a javascript min file is produced. Can I copy this js file in the main.js file? Or is there a better procedure, importing individual files?

Thank you

​​​​​​​Francesco

1 Answer 1

1

In your theme you are free to create the structure you need for your JS, as long you do not override elements from the parent theme. you can check the final result in the build folder. An option is to use your src/js folder and to include in templates you can use:

<script src="${javascript_folder}/example.js"></script>

Considering that you have something like this in your init:

<#assign
    css_folder = theme_display.getPathThemeCss()
    images_folder = theme_display.getPathThemeImages()
    javascript_folder = theme_display.getPathThemeJavaScript()
    templates_folder = theme_display.getPathThemeTemplates()

    full_css_path = fullCssPath
    full_templates_path = fullTemplatesPath
/>
3
  • Hi Victor, Thanks for the reply. The problem is not the path. Currently I have already done as you suggested by calling the scripts in portal_normal. However, I believe there is a better and cleaner solution.. Feb 21, 2019 at 9:42
  • This is the normal path, as adding all to the main.js might not be possible. You can however copy your bootstrap theme artifacts as you asked, as long it is compatible with the version used by liferay, as liferay comes with bootstrap on it already. PS, check the version of bootstrap used by your liferay version - the current one is bootstrap 4.0 (4.1 will cause issues, I have seen issues myself)
    – Victor
    Feb 21, 2019 at 17:38
  • The bootstrap version is ok. For now I put everything in main.js and it works, while from portal_normal I have included any external libraries. But I hope there is an alternative, better and cleaner method. Thank you so much. Feb 22, 2019 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.