Tapestry 4.1 - using a Script component with an external js
-
12-09-2019 - |
Question
Is it possible to use a @Script component to render a script tag pointing to a js file hosted on a different server?
Basically, I need to inject a script tag such as:
<script src="http://otherserver.com/script.js"></script>
but I need to have it render in the head, or at least before other tapestry scripts are rendered.
Thanks, Paul.
Solution
If you're using the Shell component , it's easy:
Shell.get(cycle).includeAdditionalContent( myHtmlForHead );
Or write a simple component that does that and reuse it in your templates.
OTHER TIPS
Assuming you're using a Shell component to wrap all your other files:
<html jwcid="@Shell" delegate="ognl:new org.apache.tapestry.components.BlockRenderer(getComponent('scriptBlock'))">
<span jwcid="scriptBlock@Block">
<script src="http://otherserver.com/script.js"></script>
</span>
...
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow