Hi team, I have an html.twig file in the location iTop portal base -> portal -> templated. I am adding a JavaScript code inside this html.twig file at the end, inside the body.
{% block pPageExtensionsScripts %}
{# UI Extensions inline JS #}
{% if app['ui_extensions_helper'].js_inline is not null %}
<script type="text/javascript"><br>
{{ app<span>['ui_extensions_helper']</span>.js_inline|raw }}<br>
</script>
{% endif %}
{% endblock %}
After adding this code, I am committing it using the toolkit. The toolkit is not showing any errors, and the commit is successful. However, when I hit the iTop URL, it crashes, and the URL is not working. If I add this code to a normal HTML file, it works fine.
If anyone has a solution for this, please provide it. Appreciate it in advance.
Last edit: Rohit Kushwaha 2023-11-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Without the error on the page it is difficult to help troubleshooting. Did you check iTop logs or PHP / apache logs?
That being said, modifying the portal files directly is not recommended as you will loose everything when upgrading the app later. Instead you should make your own iTop extension and use the \AbstractPortalUIExtension::GetJSInline() API instead.
Check this page to learn more on how to make your own extension
Check this extension for an example on how to add you own JS script.
Hope it helps,
Guillaume
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi team, I have an html.twig file in the location iTop portal base -> portal -> templated. I am adding a JavaScript code inside this html.twig file at the end, inside the body.
{% block pPageExtensionsScripts %}
{# UI Extensions inline JS #}
{% if app['ui_extensions_helper'].js_inline is not null %}
<script type="text/javascript"><br> {{ app<span>['ui_extensions_helper']</span>.js_inline|raw }}<br> </script>
{% endif %}
{% endblock %}
**
<script> (function(d,t) { var BASE_URL="myurl"; var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=BASE_URL+"/packs/js/sdk.js"; g.defer = true; g.async = true; s.parentNode.insertBefore(g,s); g.onload=function(){ window.abc.run({ websiteToken: 'jaklfjoirijojnag', baseUrl: BASE_URL }) } })(document,"script"); </script>**
After adding this code, I am committing it using the toolkit. The toolkit is not showing any errors, and the commit is successful. However, when I hit the iTop URL, it crashes, and the URL is not working. If I add this code to a normal HTML file, it works fine.
If anyone has a solution for this, please provide it. Appreciate it in advance.
Last edit: Rohit Kushwaha 2023-11-22
Hello Rohit,
Which version of iTop are you running?
Hi @Guillaume,
I am using the iTop community version 3.0.3
Without the error on the page it is difficult to help troubleshooting. Did you check iTop logs or PHP / apache logs?
That being said, modifying the portal files directly is not recommended as you will loose everything when upgrading the app later. Instead you should make your own iTop extension and use the
\AbstractPortalUIExtension::GetJSInline()
API instead.Check this page to learn more on how to make your own extension
Check this extension for an example on how to add you own JS script.
Hope it helps,
Guillaume