You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I did a loop (there is no internal loop support, I had to use standard php foreach) and inside the loop I imported by small template. That small template had many sections defined. The content of these sections got exponentially bigger and repeated by every iteration in the final rendered html.
I think, Foil does not understand loops, so it keep the html generated from section of last iteration and keep appending over it. What outputs is like:
header
imported_section_1
imported_section_1
imported_section_2
imported_section_1
imported_section_2
imported_section_3
footer
when the output should have been
header
imported_section_1
imported_section_2
imported_section_3
footer
How to fix this behavior?
The text was updated successfully, but these errors were encountered:
@thevikas if I understand well, you want that next item in the loop replace the same section in previous one.
This replace behaviour is not the default in Foil.
If you have a look at documentation http://www.foilphp.it/docs/TEMPLATES/INHERITANCE.html expecially in the section "Functions Summary" you'll see that there're 3 functions to "close" a section: append(), replace() and stop().
As you can guess, append() makes the section content be appended to the content fo same section, if it exists, and replace() make the content above it replace any previous content in the same section.
The stop() behaviour, is a bit different. When used in a layout, it is pretty much used to define a "default" content for the section.
When used in a child template, it acts as append(). However, you can make it act as replace() setting the "section_def_mode" option when you instantiate the Foil engine.
That option is set to SectionInterface::MODE_APPEND but you can change it to SectionInterface::MODE_REPLACE to make stop() acts as replace() by default.
My suggestion is to use stop() in layouts (in file that are wrote to be extended). And in child templates use append() or replace() to make clear what your intention is. This will make you templates better readable.
Helpers linked above may be helpful or not depending your use case, but the usage of PHP core statements and functions (like foreach) is not considered bad at all in Foil, in fact, the whole point of a template engine for PHP templates is to be able to use PHP core constructs.
I did a loop (there is no internal loop support, I had to use standard php foreach) and inside the loop I imported by small template. That small template had many sections defined. The content of these sections got exponentially bigger and repeated by every iteration in the final rendered html.
I think, Foil does not understand loops, so it keep the html generated from section of last iteration and keep appending over it. What outputs is like:
when the output should have been
How to fix this behavior?
The text was updated successfully, but these errors were encountered: