processwire/processwire-requests

Markup Regions without PageRender

Opened this issue · 2 comments

From what I understand, region replacement occurs when a page is rendered.

There are times where I may want to do region replacement, but not when a page is rendered.

Does it make sense to create some sort of helper that would take this (pretend this content was simply stored in a string):

<div id="foo"><p>hello</p></div>
<div id="foo" pw-append><p>goodbye</p></div>

And transform it into this?

<div id="foo"><p>hello</p><p>goodbye</p></div>

Example use case... I built a calendar with HTMX and it uses a URL hook to render the calendar, but without the events inside each calendar day. It would be cool if I could render the calendar, then render the events separately, and using the feature I'm discussing, "inject" the events into the specific calendar days (similar to my example above with region IDs and such). Because it's a URL hook, it would not get rendered by PageRender, so having this helper would be pretty slick.

@jlahijani This is something that the WireMarkupRegions class can already do of you instantiate it on your own. But are you looking for a simpler API? If so, can you approximate the type of API call you'd want to make for the HTMX example you mentioned? Maybe something like this below? (this is not how it works at present, I'm just wondering if this is what you are looking for):

$originalMarkup = '<div id="foo"><p>hello</p></div>';
$addedMarkup = '<div id="foo" pw-append><p>goodbye</p></div>';
$newMarkup = $markupRegions->render($originalMarkup, $addedMarkup); 

Hi @ryancramerdesign . A render method as you described certainly sounds convenient and fitting.