Add a ZML Snippet to a Page | Zoho Creator Help

Creating and managing ZML snippets

Snippets are stand-alone, re-usable code pieces that can add additional functionality. ZML or Zoho Markup Language is a simple markup language used to create pages in your Zoho Creator Appliction. Using ZML, you can build various elements of your page, create a display structure to arrange these elements on the page, add descriptive and logical properties to these elements, format the contents of these elements and more. Learn more

Adding a ZML snippet to your page

  1. Edit your app.
  2. Navigate to the Design tab and open the page builder.
  3. In the page builder, click Snippets on the left, then drag and drop the ZML Snippet on to the required position on your page. The ZML Snippet editor will appear.


  4. Add the required ZML code. Below image shows a reference code to add a panel in the ZML snippet.


  5. Click Save and close the editor.
  6. Access your live page and the respective snippet will be displayed.

Adding multiple arguments to a function in ZML snippets

ZML snippets also allow for the passing of multiple arguments in functions. Let's assume an application Resource Management for which we have a function along with a ZML snippet that allows us to pass an email address as page variables and send the mail on click of a button in the page. Here, ${frmAdrs} and ${toAdrs} are the two page variables.


The ZML snippet for the button.
  1. <%{
  2. %>
  3. <panel elementName="Panel">
      <pr width='fill' height='fill'>
        <pc padding='20px' bgColor='#FFFFFF' width='100%' hAlign='center' vAlign='middle'>
          <pr width='auto' height='auto'>
            <pc>
              <button marginLeft='0px' marginRight='0px' marginBottom='0px' marginTop='0px' action='ExecuteFunction' parameters='${frmAdrs},${toAdrs}' functionName='toSendMail' color='#FFFFFF' size='16px' text='Send Mail' type='flat' bgColor='#0072F4' cornerRadius='3px' /> </pc>
          </pr>
        </pc>
      </pr>
    </panel>
  4. <%
The function to pass the parameters.
  1. void toSendMail( string FrmAdrs, string ToAdrs )
    {
    sendmail
        [
        from: input.FrmAdrs
        to: input.ToAdrs
        subject: "Send mail task"
        message: "Message"
        ]
    }

Things to know

Let's say you have a form that contains a multi-line field. If you've entered your input in the multi-line field with line breaks, the same is displayed in your report. However, the line breaks will not appear if you use the same multi-line field as inside the <text> tag in a ZML snippet.
To ensure that line breaks appear when you enter paragraphs or a list of data that you intend to be vertical, you can use the below script to achieve the same.
  1. <%{
  2.     newLine = hexToText("0A");
  3.     html_lineBreak = "<br>";
  4.     encoded_lineBreak = html_lineBreak.replaceAll("<","&lt;").replaceAll(">","&gt;");
  5.     var = Form[ID != null].Multi_Line_Field;
  6.     new_text = var.replaceAll(newLine,encoded_lineBreak);
  7.     %>
  8. <panel> 
  9.     <pr hAlign='left'>
  10.         <pc>
  11.             <text renderAsHtml='true' value='<%=new_text%>'></text>
  12.         </pc>
  13.     </pr>
  14. </panel>
  15. <%
  16. }%>
Using this code, your input is reflected just as you have entered.

Input:
      

Output: