fetch(href, {
headers: {
Accept: "text/vnd.turbo-stream.html",
},
})
.then(r => r.text())
.then(html => Turbo.renderStreamMessage(html))
// optionally reflect the url .then(_ => history.replaceState(history.state, "", href))
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static values = {
src: String,
}
connect() {
fetch(this.srcValue, {
headers: {
Accept: "text/vnd.turbo-stream.html",
},
}).then(r => r.text())
.then(html => Turbo.renderStreamMessage(html))
}
}
In this example, the show action responds to a turbo_stream format and renders the details partial as a turbo_stream.append operation. The details partial should contain the HTML that you want to append to the DOM.
You can then call Turbo.visit from a Stimulus controller or another JavaScript function to trigger the partial to be appended to the DOM. For example:
In this example, the showDetails method is triggered by a button click or other event. It calls Turbo.visit to navigate to the show action for the order and returns the response. The html variable is set to the HTML of the turbo_stream.append operation, which is then inserted into the DOM using innerHTML.