Using js in edge templates #3870
Replies: 2 comments 2 replies
-
You have several options to include client side Javascript. You can add it via a script tag or install via NPM and import your scripts in https://docs.adonisjs.com/guides/installation#configure-webpack-encore |
Beta Was this translation helpful? Give feedback.
-
The common usage is: edge
myCode.js
app.js
The problem with passing data from server side is that Webpack bundled scripts are not global, so you cannot reference them. The easy solution is using Alpinejs. You can pass data in the HTML template to Alpine methods.
The more involved solution is looking into this: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
is it possible to use javascript in edge templates?
For example:
I render a view with an error in its state. I want to show the error on page load via a 3rd party alert plugin. Not sure how to realize that.
Does anyone have tips on how to make it work?
The view is rendered server-side, but is there anything I can do to trigger client-side js on render?
Thanks!
Mariano
Beta Was this translation helpful? Give feedback.
All reactions