How do I properly process HTML tag and its body in my own Element Model Processor? For example, I have the following HTML structure:
<my:form id="some_id">
<my:input type="text" name="input-1"/>
<my:input type="number" name="input-2"/>
</my:form>
I would like to alter both the wrapping my:form
tag by adding some generated attribute so that output would look something like <form id="some_id" other-attr="_generated_value_">...</form>
and process each of the inner my:input
by adding an attribute with form id to each of those inputs (and generally process those tags as they should be), e.g. <input type="text" name="input-1" id="generated_1" form-id="some_id">
. Normally my:input
is processed by my AbstractAttributeTagProcessor
extension.
As of now I have extended the AbstractElementModelProcessor
creating the processor like this:
public class MyFormProcessor extends AbstractElementModelProcessor {
private static final String ELEMENT_NAME = "form";
private static final int PRECEDENCE = 1000;
public MyFormProcessor( final String dialectPrefix ) {
super(
TemplateMode.HTML,
dialectPrefix, // dialect prefix - 'my' in this case
ELEMENT_NAME,
true, // filter by element name prefix
null,
false,
PRECEDENCE
);
}
@Override
protected void doProcess( ITemplateContext context,
IModel model,
IElementModelStructureHandler structureHandler ) {
// what goes here?
}
}
The processor is registered correctly and does turm the form and its body into a series of events, but I'm yet to figure out how to modify the model
properly as I cannot find any modification methods on its elements.
Thanks in advance for any guidance!