用Twig装饰模板而不是包含它

I'm working on a small ORM for my work, based on an Active Record system. So all models extend a generated base model (for example : Foo will extends BaseFoo, the abstract BaseFoo class will be generated by a command).

The abstract model generation is based on a Twig template, including some parts of other templates (attributes, getters & setters, main methods, etc).

But the ORM must handle a behavior system. So a behavior should be able to decorate the main template. But with the Twig hierarchical layout system, I don't find a way to properly decorate my template, by injecting some lines in the main template. I can handle it with the embed tag, calling the base template and overriding blocks. But when there is more than one behavior, the idea fails because the embed tag rewrites the main template so it will write twice times the model (class BaseFoo { code overrided by behavior1 } class BaseFoo { code overrided by behavior2 }.

I thought about creating some new tags : replace "line" by "line", append "line" after "line" or prepend "line" before "line". But I want to be sure that there isn't a better way to decorate a Twig template, like for example, generating one by one the template for all behaviors : the first behavior will override the main template and the next behavior will override the previous generated template by calling the Twig function template_from_string().

What do you think about the possibility of decorating a Twig template ?