Foil icon indicating copy to clipboard operation
Foil copied to clipboard

Multiple section replace don't work

Open yoshkinawa opened this issue 6 years ago • 2 comments

Hi Giuseppe, I've created a simple demo for, apparently, a bug I have found.

I have a base template called: baseTemplate

<!DOCTYPE HTML>
<html>
	<head>
	</head>
    <body>
	<? $this->section('body') ?>aaa<? $this->stop() ?>
    </body>
</html>

I have a second template called: templateA

<? $this->layout('_layout/baseTemplate') ?>
<? $this->section('body') ?>bbb<? $this->replace() ?>

I have a third template called: templateB

<? $this->layout('_layout/templateA') ?>
<? $this->section('body') ?>ccc<? $this->replace() ?>

While the result is supposed to be: ccc, in fact, it shows bbb

If I change the the section ending in templateA from replace() to stop(), I get ccc.

I would we very thankful if you could take a look at it, and fix it. :) Yoshi.

yoshkinawa avatar May 22 '18 19:05 yoshkinawa

In your example, wouldn't it be more useful to let templateB also have layout baseTemplate ?

MichielioZ avatar Oct 16 '18 10:10 MichielioZ

Not for my needs. baseTemplate represents the base template of any page on my website. templateA represents a template of a specific page templateB represent a modified version of the same page. For example, if templateA is a generic version of a page, templateB is the same page seen by a subscribed user.

At the moment I'm using a workaround. I've created a function that replaces the replace() function. If this is the first time the function is called, it returns $this->replace(), If not, it returns $this->stop()

This is the function:

$FOIL_REPLACE_TRACK = [];
function foil_replace( $foilRef, $sectonName ){
	global $FOIL_REPLACE_TRACK;
	if( isset( $FOIL_REPLACE_TRACK[$sectonName] )){
		$foilRef->stop();
	} else {
		$FOIL_REPLACE_TRACK[$sectonName] = TRUE;
		$foilRef->replace();
	}
}

It is used like this:

<? $R->section( 'sectionName' ) ?>
     some content
<? foil_replace( $R,'sectionName' ) ?>

yoshkinawa avatar Oct 17 '18 08:10 yoshkinawa