inspiredminds/contao-turbo-helper

This extension helps with the usage of Turbo in Contao applications.

Fund package maintenance!
fritzmg

Installs: 582

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:contao-bundle

1.3.1 2024-12-11 10:49 UTC

This package is auto-updated.

Last update: 2024-12-11 10:49:23 UTC


README

Contao Turbo Helper

This extension helps with the usage of Turbo in Contao applications.

  • It provides a Turbo Frame wrapper as content elements.
  • It forces the status code to 422 Unprocessable Entity when a Contao form does not validate.
  • It forces a JavaScript load of a form's target URL, in case it would redirect to a URL outside the current domain.

Streams

You can also create streams within your legacy Contao PHP templates:

<!-- templates/mod_newslist.html5 -->
<?php $this->startTurboStream(); ?>
  <turbo-stream action="append" target="mod-newslist-articles-<?= $this->id ?>">
    <template><?= implode('', $this->articles) ?></template>
  </turbo-stream>
  <turbo-stream action="update" target="mod-newslist-pagination-<?= $this->id ?>">
    <template><?= $this->pagination ?></template>
  </turbo-stream>
<?php $this->endTurboStream(); ?>

<?php $this->extend('mod_newslist'); ?>

<?php $this->block('content'); ?>

  <?php if (empty($this->articles)): ?>
    <p class="empty"><?= $this->empty ?></p>
  <?php else: ?>
    <div id="mod-newslist-articles-<?= $this->id ?>">
      <?= implode('', $this->articles) ?>
    </div>
    <div id="mod-newslist-pagination-<?= $this->id ?>">
      <?= $this->pagination ?>
    </div>
  <?php endif; ?>

<?php $this->endblock(); ?>

The server will then respond with these streams if there was a request with Accept: text/vnd.turbo-stream.html (e.g. through a link with data-turbo-stream).