Hi, folks. I've been working on converting my plugin structtemplate from special patterns to entry and exit patterns, which is working, but I've run into a new issue I could use some thoughts on.
I don't want to render the contents between the entry and exit patterns as they are encountered, but store them up until I reach the exit pattern, then render the whole lot in a loop with one instance for each line of the data found in Struct. I've got the following patterns at the moment:
entry: <struct-template-block\b.*?>\n----+ *data *----+\n.*?\n----+(?=.*?\n<\/struct-template-block>)
internal: (?-s)\n(?!<\/struct-template-block>).*
exit: \n<\/struct-template-block>
This matches a syntax of:
<struct-template-block>
---- data ----
[any struct table configuration]
----
[lines of the template, with interpolation markers]
</struct-template-block>
The internal pattern matches every line between it and the exit pattern so they don't get consumed by other syntaxes. With this setup, my plugin's handle()
and render()
methods get called at least twice (entry and exit), and once for each line between. [Aside: I may be able to refactor this to make it simpler based on which syntaxes I accept inside mine.]
My current thinking is to build up the template in the filesystem (perhaps as metadata), then use the handler/renderer in the exit pattern to output the full template as many times as necessary, but I was wondering if there's any way to communicate between the times my methods are called in memory, as that will be much faster?