Now I need a switch to control the div. If I have a special field the div should not appear. So I’m building this in “good old” manner of Custom Content Shortcode:
Would it work if the div is there but has a different class? If so you can just set the class using a local variable, that would allow the template to pass the validation.
Another thought - could you set the loop content as a local variable and then output that within the div (or not) depending on whether or not the field exists?
This seems more complicated than setting the class with the local variable if it’s just for styling, but if you can’t have the div at all if the field doesn’t exist then in theory this would be a way to do it (I gave it a quick test with a relatively simple loop and it worked fine).
Or, if this doesn’t work because of some change in context between where the content is saved and called, you can use <Set template=loop_content> instead, and when you call it with <Get> the fields within will run in the context in which they’re called instead of the context in which they’re set