esmero / format_strawberryfield

Set of Display formatters, extractors and utils to make Strawberry field data glow
GNU Lesser General Public License v3.0
6 stars 9 forks source link

Load Views via Ajax using data selectors provided by Archipelago #427

Closed DiegoPino closed 3 months ago

DiegoPino commented 3 months ago

What?

Many times one (you/me/them) need to load dynamically based on interaction or just async on load a list of things (a View). Might be because the list depends on conditions set on a Metadata Display with arguments, or on interaction (clicks). Writing code to do that is a bit advanced and might require rewiring some stuff. But all our users have access to editing their twig templates, so following the Bootstrap idea, let's use data- selector to give Ajax/JS commands on what can be done.

The idea is simple:

You output this:

<button id="aRequiredID" 
data-sbf-view-id="creative_work_series_children" 
data-sbf-view-display-id="block_1" 
data-sbf-view-arguments="45" 
data-sbf-view-render-target="the_target" 
data-sbf-view-event="click">
Click me to load creative_work_series_children View 
with block_1 display 
passing argument 45 
inside another DIV with a class named "js-view-dom-id-the_target"
</button>

<div class="js-view-dom-id-the_target">HERE WILL BE MY VIEW LOADED</div>
DiegoPino commented 3 months ago

resolved via https://github.com/esmero/format_strawberryfield/commit/8984758406ad600ee9846cc643a8d86a5d00a27e