Skip to content

Instantly share code, notes, and snippets.

@juque
Created March 13, 2024 21:44
Show Gist options
  • Save juque/932edfb06c814894245d59166947e305 to your computer and use it in GitHub Desktop.
Save juque/932edfb06c814894245d59166947e305 to your computer and use it in GitHub Desktop.
PHP + Turbo + Stimulus
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP + Turbo + Stimulus</title>
<script src="/javascript/turbo.es2017-umd.js"></script>
<script src="/javascript/stimulus.umd.js"></script>
<script src="/javascript/controllers/index_controller.js" data-turbolinks-track="reload"></script>
</head>
<body>
<h1>PHP + Turbo + Stimulus</h1>
<div data-controller="index">
<input data-index-target="name" type="text" />
<button data-action="click->index#greet">
Greet
</button>
<span data-index-target="output"></span>
</div>
</body>
</html>
const application = Stimulus.Application.start();
class IndexController extends Stimulus.Controller {
static targets = [ "name", "output" ]
connect() {
console.log('Connected!')
}
greet() {
this.outputTarget.textContent = `Hello, ${this.nameTarget.value}!`
}
}
application.register("index", IndexController);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment