XF 2.1 Regex Help

Well, I have another one I am stumped on. I need to find this in the PAGE_CONTAINER:
HTML:
            <xf:if is="$sidebar">
                <div class="p-body-sidebar">
                    <xf:ad position="container_sidebar_above" />
                    <xf:foreach loop="$sidebar" value="$sidebarHtml">
                        {$sidebarHtml}
                    </xf:foreach>
                    <xf:ad position="container_sidebar_below" />
                </div>
            </xf:if>

In XF 2.0.x I did this:
#<xf:if is="\$sidebar">.*<xf:ad position="container_sidebar_below" \/>.*<\/xf:if>#Us

Problem is, in XF 2.2.x its returning all of this:
HTML:
            <xf:if is="$sidebar">
                <div class="p-body-sidebarCol"></div>
            </xf:if>

            <xf:if is="$sideNav">
                <div class="p-body-sideNav">
                    <div class="p-body-sideNavTrigger">
                        <xf:button class="button--link" data-xf-click="off-canvas" data-menu="#js-SideNavOcm">
                            {{ $sideNavTitle ?: phrase('navigation') }}
                        </xf:button>
                    </div>
                    <div class="p-body-sideNavInner" data-ocm-class="offCanvasMenu offCanvasMenu--blocks" id="js-SideNavOcm" data-ocm-builder="sideNav">
                        <div data-ocm-class="offCanvasMenu-backdrop" data-menu-close="true"></div>
                        <div data-ocm-class="offCanvasMenu-content">
                            <div class="p-body-sideNavContent">
                                <xf:ad position="container_sidenav_above" />
                                <xf:foreach loop="$sideNav" value="$sideNavHtml">
                                    {$sideNavHtml}
                                </xf:foreach>
                                <xf:ad position="container_sidenav_below" />
                            </div>
                        </div>
                    </div>
                </div>
            </xf:if>

            <div class="p-body-content">
                <xf:ad position="container_content_above" />
                <div class="p-body-pageContent">{$content|raw}</div>
                <xf:ad position="container_content_below" />
            </div>

            <xf:if is="$sidebar">
                <div class="p-body-sidebar">
                    <xf:ad position="container_sidebar_above" />
                    <xf:foreach loop="$sidebar" value="$sidebarHtml">
                        {$sidebarHtml}
                    </xf:foreach>
                    <xf:ad position="container_sidebar_below" />
                </div>
            </xf:if>
 
This will do what you want, but only for 2.2 (I think). There is a better way I'm sure, it's just too early...

Find: #(<xf:if is="\$sidebar">.*\/xf:if>)(.*)(<xf:if is="\$sidebar">.*\/xf:if>)#sU
Replace: $1$2Test $3 contains the sidebar html
 
Try #(^[\s]*<xf:ad position="container_content_below".*?)(<xf:if is="\$sidebar.*?>)(.*?)(<\/xf:if>)#sim.

Okay, this is not quite right. See the attached screenshots

Template Modification in XF 2.1
Screenshot (1).webp

Template Modification in 2.2
Screenshot (2).webp
 
Maybe a basic question...

Is it possible with regex to turn these two expressions into one?

<xf:if is="$xf.reply.template == 'forum_list'">

<xf:if is="$xf.reply.template == 'forum_view'">

If so, can you show me how?
 
Top Bottom