@@ -166,6 +166,17 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc
166
166
*/
167
167
public function renderParentBlock ($ name , array $ context , array $ blocks = [])
168
168
{
169
+ if (!$ this ->useYield ) {
170
+ if ($ this ->env ->isDebug ()) {
171
+ ob_start ();
172
+ } else {
173
+ ob_start (function () { return '' ; });
174
+ }
175
+ $ this ->displayParentBlock ($ name , $ context , $ blocks );
176
+
177
+ return ob_get_clean ();
178
+ }
179
+
169
180
$ content = '' ;
170
181
foreach ($ this ->yieldParentBlock ($ name , $ context , $ blocks ) as $ data ) {
171
182
$ content .= $ data ;
@@ -189,6 +200,26 @@ public function renderParentBlock($name, array $context, array $blocks = [])
189
200
*/
190
201
public function renderBlock ($ name , array $ context , array $ blocks = [], $ useBlocks = true )
191
202
{
203
+ if (!$ this ->useYield ) {
204
+ $ level = ob_get_level ();
205
+ if ($ this ->env ->isDebug ()) {
206
+ ob_start ();
207
+ } else {
208
+ ob_start (function () { return '' ; });
209
+ }
210
+ try {
211
+ $ this ->displayBlock ($ name , $ context , $ blocks , $ useBlocks );
212
+ } catch (\Throwable $ e ) {
213
+ while (ob_get_level () > $ level ) {
214
+ ob_end_clean ();
215
+ }
216
+
217
+ throw $ e ;
218
+ }
219
+
220
+ return ob_get_clean ();
221
+ }
222
+
192
223
$ content = '' ;
193
224
foreach ($ this ->yieldBlock ($ name , $ context , $ blocks , $ useBlocks ) as $ data ) {
194
225
$ content .= $ data ;
@@ -331,6 +362,26 @@ public function display(array $context, array $blocks = []): void
331
362
332
363
public function render (array $ context ): string
333
364
{
365
+ if (!$ this ->useYield ) {
366
+ $ level = ob_get_level ();
367
+ if ($ this ->env ->isDebug ()) {
368
+ ob_start ();
369
+ } else {
370
+ ob_start (function () { return '' ; });
371
+ }
372
+ try {
373
+ $ this ->display ($ context );
374
+ } catch (\Throwable $ e ) {
375
+ while (ob_get_level () > $ level ) {
376
+ ob_end_clean ();
377
+ }
378
+
379
+ throw $ e ;
380
+ }
381
+
382
+ return ob_get_clean ();
383
+ }
384
+
334
385
$ content = '' ;
335
386
foreach ($ this ->yield ($ context ) as $ data ) {
336
387
$ content .= $ data ;
@@ -348,27 +399,7 @@ public function yield(array $context, array $blocks = []): iterable
348
399
$ blocks = array_merge ($ this ->blocks , $ blocks );
349
400
350
401
try {
351
- if ($ this ->useYield ) {
352
- yield from $ this ->doDisplay ($ context , $ blocks );
353
-
354
- return ;
355
- }
356
-
357
- $ level = ob_get_level ();
358
- ob_start ();
359
-
360
- foreach ($ this ->doDisplay ($ context , $ blocks ) as $ data ) {
361
- if (ob_get_length ()) {
362
- $ data = ob_get_clean ().$ data ;
363
- ob_start ();
364
- }
365
-
366
- yield $ data ;
367
- }
368
-
369
- if (ob_get_length ()) {
370
- yield ob_get_clean ();
371
- }
402
+ yield from $ this ->doDisplay ($ context , $ blocks );
372
403
} catch (Error $ e ) {
373
404
if (!$ e ->getSourceContext ()) {
374
405
$ e ->setSourceContext ($ this ->getSourceContext ());
@@ -386,12 +417,6 @@ public function yield(array $context, array $blocks = []): iterable
386
417
$ e ->guess ();
387
418
388
419
throw $ e ;
389
- } finally {
390
- if (!$ this ->useYield ) {
391
- while (ob_get_level () > $ level ) {
392
- ob_end_clean ();
393
- }
394
- }
395
420
}
396
421
}
397
422
@@ -418,27 +443,7 @@ public function yieldBlock($name, array $context, array $blocks = [], $useBlocks
418
443
419
444
if (null !== $ template ) {
420
445
try {
421
- if ($ this ->useYield ) {
422
- yield from $ template ->$ block ($ context , $ blocks );
423
-
424
- return ;
425
- }
426
-
427
- $ level = ob_get_level ();
428
- ob_start ();
429
-
430
- foreach ($ template ->$ block ($ context , $ blocks ) as $ data ) {
431
- if (ob_get_length ()) {
432
- $ data = ob_get_clean ().$ data ;
433
- ob_start ();
434
- }
435
-
436
- yield $ data ;
437
- }
438
-
439
- if (ob_get_length ()) {
440
- yield ob_get_clean ();
441
- }
446
+ yield from $ template ->$ block ($ context , $ blocks );
442
447
} catch (Error $ e ) {
443
448
if (!$ e ->getSourceContext ()) {
444
449
$ e ->setSourceContext ($ template ->getSourceContext ());
@@ -456,12 +461,6 @@ public function yieldBlock($name, array $context, array $blocks = [], $useBlocks
456
461
$ e ->guess ();
457
462
458
463
throw $ e ;
459
- } finally {
460
- if (!$ this ->useYield ) {
461
- while (ob_get_level () > $ level ) {
462
- ob_end_clean ();
463
- }
464
- }
465
464
}
466
465
} elseif ($ parent = $ this ->getParent ($ context )) {
467
466
yield from $ parent ->unwrap ()->yieldBlock ($ name , $ context , array_merge ($ this ->blocks , $ blocks ), false , $ templateContext ?? $ this );
0 commit comments