When creating custom PDF templates, keywords provide you with the ease of providing HTML patterns for each control in a form. The Parser traverses each control, then parses the HTML template to find the most appropriate HTML pattern for a control. In some cases, however, more than one HTML pattern can match the criteria required by a control.


Suppose you created a Textbox control with the identifier ‘textbox1’, and have the following HTML patterns in your template.

<tr class="mt_control c_textbox">

   <td class="FieldLabel">Label</td>

   <td class="FieldValue">Value</td>

</tr>

<tr class="mt_identifier textbox1 ">

   <td class="FieldLabel">Label</td>

   <td class="FieldValue">Value</td>

</tr>

<tr class=" FieldDataRow ">

   <td class="FieldLabel">Label</td>

   <td class="FieldValue">Value</td>

</tr>


As you can see, there are three HTML patterns, each of which can be a match for textbox1.


The first pattern can be a match because it defines the style of all Textbox controls. The second pattern can also be a match because it specifically defines the style of textbox1. Meanwhile, the third pattern has class ‘FieldDataRow’, which is used to define a generic pattern for all controls.


This is where HTML Parser prioritization is necessary.


Miracle Mobile Forms’ Parser always prioritizes the most precise pattern. In the aforementioned example, the second pattern is the most specific one among the three because it explicitly mentions textbox1.


If a specific pattern hasn’t been defined, the Parser looks for the mt_identifier element. If it isn’t found, it looks for the mt_control element. If that too isn’t found, it looks for the FieldDataRow element, which is used as the default pattern for any control.


The Parser also takes into consideration the current scope or control hierarchy while choosing the best matching pattern. In general, the Parser first analyzes where the control stands in the control hierarchy, and then tries finding a match in that scope. If a matching pattern is found, it uses that. Otherwise, it goes up in the hierarchy and tries to find a matching pattern. This process is carried out until the Parser reaches the root element of the HTML template.


Here is an example:

<tr class="mt_control c_textbox">

   <td class="FieldLabel myStyle1">Label</td>

   <td class="FieldValue myStyle1">Value</td>

</tr>

<div class="mt_control c_layout">

   <tr class="mt_control c_textbox">

      <td class="FieldLabel myStyle2">Label</td>

      <td class="FieldValue myStyle2">Value</td>

   </tr>

</div>


As you can see, there are two HTML patterns for Textbox controls: one on root level and another inside a Layout control pattern.


For all the Textbox controls placed inside a Layout, the latter pattern will be used. As for the rest of the Textbox controls, the root pattern will be used.


To summarize this article:

  • If more than one HTML pattern matches the criteria of a control, the Parser will use the one which is most specific.
  • The Parser takes into consideration the current control hierarchy while finding the HTML pattern for a control. It prioritizes the current scope and continues traversing up the hierarchy until a matching HTML pattern is found, or a root element is reached.