@@ -85,12 +85,32 @@ public static function create(Tag $tag, TemplateParser $parser): \Generator
8585
8686 public function print (PrintContext $ context ): string
8787 {
88- $ dynamic = $ this ->block ->isDynamic ();
89- if (!$ dynamic ) {
88+ if (!$ this ->block ->isDynamic ()) {
9089 $ context ->addBlock ($ this ->block );
9190 }
9291
93- $ snippetContent = $ context ->format (
92+ if ($ this ->htmlElement ) {
93+ try {
94+ $ inner = $ this ->htmlElement ->content ;
95+ $ this ->htmlElement ->content = new AuxiliaryNode (fn () => $ this ->printContent ($ context , $ inner ));
96+ return $ this ->content ->print ($ context );
97+ } finally {
98+ $ this ->htmlElement ->content = $ inner ;
99+ }
100+ } else {
101+ return <<<XX
102+ echo '<div {$ this ->printAttribute ($ context )}>';
103+ {$ this ->printContent ($ context , $ this ->content )}
104+ echo '</div>';
105+ XX ;
106+ }
107+ }
108+
109+
110+ private function printContent (PrintContext $ context , AreaNode $ inner ): string
111+ {
112+ $ dynamic = $ this ->block ->isDynamic ();
113+ $ res = $ context ->format (
94114 <<<'XX'
95115 $this->global->snippetDriver->enter(%node, %dump) %line;
96116 try {
@@ -103,34 +123,20 @@ public function print(PrintContext $context): string
103123 $ dynamic ? new AuxiliaryNode (fn () => '$ʟ_nm ' ) : $ this ->block ->name ,
104124 $ dynamic ? SnippetDriver::TypeDynamic : SnippetDriver::TypeStatic,
105125 $ this ->position ,
106- $ this -> htmlElement -> content ?? $ this -> content ,
126+ $ inner ,
107127 );
108128
109- if (!$ dynamic ) {
110- $ this ->block ->content = $ snippetContent ;
111- $ snippetContent = $ context ->format (
112- '$this->renderBlock(%node, [], null, %dump) %line; ' ,
113- $ this ->block ->name ,
114- Template::LayerSnippet,
115- $ this ->position ,
116- );
129+ if ($ dynamic ) {
130+ return $ res ;
117131 }
118132
119- if ($ this ->htmlElement ) {
120- try {
121- $ saved = $ this ->htmlElement ->content ;
122- $ this ->htmlElement ->content = new AuxiliaryNode (fn () => $ snippetContent );
123- return $ this ->content ->print ($ context );
124- } finally {
125- $ this ->htmlElement ->content = $ saved ;
126- }
127- } else {
128- return <<<XX
129- echo '<div {$ this ->printAttribute ($ context )}>';
130- {$ snippetContent }
131- echo '</div>';
132- XX ;
133- }
133+ $ this ->block ->content = $ res ;
134+ return $ context ->format (
135+ '$this->renderBlock(%node, [], null, %dump) %line; ' ,
136+ $ this ->block ->name ,
137+ Template::LayerSnippet,
138+ $ this ->position ,
139+ );
134140 }
135141
136142
0 commit comments