- Fixed a bug that appeared deeper when rendering a block inside the slot of another block
This commit is contained in:
		
							parent
							
								
									934643214e
								
							
						
					
					
						commit
						d22d26c9c8
					
				| @ -8,15 +8,20 @@ class BlockToken implements ControlStructure { | ||||
| 
 | ||||
|     public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string | ||||
|     { | ||||
|         static $depth = 0; | ||||
|         static $slotDefinitions = []; | ||||
| 
 | ||||
|         # dump($depth, $token, $arguments, $slotDefinitions);
 | ||||
| 
 | ||||
|         switch($token) { | ||||
|             case "block": | ||||
|                 $slotDefinitions[] = $this->slotDefinitions(); | ||||
|                 $depth++; | ||||
| 
 | ||||
|                 return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>"; | ||||
| 
 | ||||
|             case "endblock": | ||||
|                 $depth--; | ||||
|                 return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>"; | ||||
| 
 | ||||
|             case "arguments": | ||||
| @ -40,14 +45,14 @@ class BlockToken implements ControlStructure { | ||||
|             case "define": | ||||
|                 list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, ""); | ||||
| 
 | ||||
|                 end($slotDefinitions)->setDefinition(eval("return $name;"), $definition); | ||||
|                 ( $slotDefinitions[$depth] ?? end($slotDefinitions) )->setDefinition(eval("return $name;"), $definition); | ||||
| 
 | ||||
|                 return <<<PHP | ||||
|                 <?php \$this->defineSlot($name, function($definition) {}); ?>
 | ||||
|                 PHP; | ||||
| 
 | ||||
|             case "slot": | ||||
|                 $def = end($slotDefinitions); | ||||
|                 $def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) ); | ||||
| 
 | ||||
|                 list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, ""); | ||||
| 
 | ||||
| @ -74,12 +79,12 @@ class BlockToken implements ControlStructure { | ||||
|                     } | ||||
| 
 | ||||
|                     return <<<PHP | ||||
|                     <?php (\$___block ?? \$this)->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | ||||
|                     <?php (\$___block ?? \$this)->slotIsSet($name) || (\$___block ?? \$this)->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | ||||
|                     PHP; | ||||
|                 } | ||||
| 
 | ||||
|             case "endslot": | ||||
|                 $def =end($slotDefinitions); | ||||
|                 $def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) ); | ||||
| 
 | ||||
|                 if ($def->hasDefinitions() ) { | ||||
|                     $definition = $def->getCurrentSlotDefinitionVars(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user