EFTEC / BladeOne

The standalone version Blade Template Engine without Laravel in a single php file and without dependencies
https://www.escuelainformatica.cl/
Other
780 stars 120 forks source link

View renders same content, when rendering twice passing different values #81

Closed AeonFr closed 5 years ago

AeonFr commented 5 years ago

Hello.

I found out Blade One is not properly injecting variables after calling the same template twice, but only if the template uses an @extends tag.

I have the following code to reproduce the issue:

$views = ROOT . '/Admin/Vistas/';
$cache = ROOT . '/Upload/cache/BladeOne/';
$bladeOne = new BladeOne($views, $cache);

$vista1 = $bladeOne->run('test', ['content' => 1]);
$vista2 = $bladeOne->run('test', ['content' => 2]);

echo $vista1;
echo $vista2;

So basically this works at expected and prints "1, 2" if the given template is something like this:

{{ $content }}

But it fails (prints "1, 1") in the following case:

# test.blade.php
@extends('test-layout')

@section('content')
    {{ $content }}
@endsection
# test-layout.blade.php
@yield('content')

Basically the issue happens when the name of one of the template's variables is equal to the name of a section.

~I know this is very easy to work around (just rename a variable or section), but on the other hand it was really difficult to identify, so I think it would be nice if this could be addressed sometime.~

Edit: This issue doesn't seem to be related to the name of the $content variable being the same as the name of the section.

I will dig a little bit in the source code if I have some time in the weekend and try to fix it.

jorgecc commented 5 years ago

done #3.28

Each section is cache. So I destroy the cache each time we run() the template.

AeonFr commented 5 years ago

Thanks! I had a hard time finding the issue when it came out. Sorry for saying I would try to fix it, I totally forgot and had other things in mind.

Thanks again