I'm just getting started with thymeleaf. What I am working on is a prototype for integrating thymeleaf/spring with magnolia cms. Therefore I created a custom include processor, that has access to the magnolia cms contents and tried to include the fragment with a new context, that itselfs includes the magnolia cms content to be rendered in the inclusion. Unfortunately I couldn't access the variables from the new context in the fragment, I guess I made something wrong there. I worked around by cloning the fragment nodes, processing them as a new Document, and then cloning them back in the original document which seems a little expensive, but at least works for now.
What I wonder now is the scope of the fragment processing, and when does fragment processing happen. Is there a simpler way to include a fragment with "scoped variables"?
From what I've managed to find out, processing is done top-down and depth-first, based on the DOM structure of your pages. Any variables declared in your markup or by processors, are available to other processors of lower priority in the element they're declared, and all child elements.
How were you setting the variables in your processors before you did your cloning workaround? I've used ProcessorResult.setLocalVariables(Map<String,Object>) in my dialect, which I think I copied from how the th:with processor works.