Jump to content

Unexpected Order with Markup Regions pw-append


gebeer
 Share

Recommended Posts

Hi there,

I'm experiencing unexpected behavior with markup regions where multiple pw-append actions are being processed in reverse order. I have been using markup regions for several years in multiple projects and never came across this. There are no project specific potential causes for my problem that I could identify. Involved HTML markup syntax is correct.

Setup
Delayed output strategy with site/templates/_main.php (simplified):

<html>
  <head>
  </head>
  <body>
    <main id="maincontent" class="content">
    </main>
  </body>
</html>

site/templates/products.php:

<div class="bg productsintrobg" pw-prepend="maincontent">
    <!-- Products Intro Section -->
    <div class="container">
        <!-- Products Intro Content -->
    </div>
</div>

<div class="bg productcatsbg" pw-append="maincontent">
    <!-- Product Categories Section -->
    <div class="container">
        <section class="productCats teasers row">
            <!-- Product categories content -->
        </section>
    </div>
</div>

Expected Behavior
Since products.php executes before _main.php and contains region actions (pw-append) that should be processed in order, the final output should show:
Products Intro Section
Product Categories Section

Actual Behavior
The sections are rendered in reverse order:
Product Categories Section
Products Intro Section

Technical Context
According to the Markup Regions documentation:

Quote

Any markup output before the <html> tag is considered to contain region actions
Any markup output after the <html> tag is considered to contain region definitions

Since products.php is processed before _main.php (using $config->appendTemplateFile = '_main.php'), the region actions in products.php are technically output "before" the <html> tag and region definitions in _main.php. Therefore, the implementation follows the documentation correctly, but the output order is reversed.

Current Workaround
Changed first section from pw-append to pw-prepend to achieve desired order:

<div class="bg productsintrobg" pw-prepend="maincontent">
    <!-- Products Intro Section -->
</div>

<div class="bg productcatsbg" pw-append="maincontent">
    <!-- Product Categories Section -->
</div>

MarkupRegions Debug Output (shows wrong order of processing):

• APPEND #maincontent with <div class="bg productcatsbg" ... +24 bytes><div class="container"> <section class="productCats teasers row"> … 14986 bytes</div>
• APPEND #maincontent with <div class="bg productsintrobg... +26 bytes><div class="container"> <article class='intro row'> … 1264 bytes</div>
• 0.0014 seconds


Environment
ProcessWire version: .3.0.243
PHP version: 8.1 (same behavior with 8.2)

Has anyone experienced this before? Couldn't find related forum posts or github issues

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...