Blogger Macro XML Template Code

Understanding about Blogger Macro XML Template Code


Blogger Macro XML Template Code

Blogger version 2 included macro functionality for all themes. This post will teach you about macros in XML template code.
What exactly are macros?
Blogger XML functions with arguments are known as macros. Those routines will process parameters and produce particular codes based on their values. A macro is divided into two parts: includable (declaration code) and include (call to action code)


Included code is often inserted after the /body> tag. The syntax is as follows: 

 
<macro:includable id='your_function_name' var='name_of_param_list'>
 <!-- output a param -->
 <data:name_of_param_list.name_of_param_1/>

 <!-- compare a param -->
 <macro:if cond='data:name_of_param_list.name_of_param_2 == 2'>
  <!-- do something here -->
 </macro:if>
</macro:includable>

For your function name, name of param list, and name of param, you may use whatever text you like. Please use the following syntax for loops and branching in your function: Blogger XML code loops and branches, but change b: with macro:.


The include code can be invoked from within the <body>.../body> tags. The syntax is as follows:

<macro:include id='name_of_macro_include' name='your_function_name'>
 <macro:param default='default-value-here' name='name_of_param_1' value='current-value-here'/>
 <macro:param default='1' name='name_of_param_2' value='10'/>
</macro:include>

Examples of Code

The included code below is a macro declaration for the emexee example function:

<macro:includable id='sneeit_example' var='my_params'>
 <macro:if cond='data:my_params.num == 0'>
  <data:my_params.message/>
 <macro:else/>
  <b:section mexpr:class='data:my_params.class' mexpr:id='data:my_params.idPrefix + &quot;-2-2&quot;'/>
 </macro:if>
</macro:includable>

Then I will call my macro function somewhere in my template with the below include code

<macro:include id='display-column-sections' name='sneeit_example'>
 <macro:param default='2' name='num' value='4'/>
 <macro:param default='div' name='idPrefix'/>
 <macro:param default='div-block' name='class'/>
 <macro:param default='&quot;Your number is empty&quot;' name='message'/>
</macro:include>

Blogger Macros Unique

For name of macro include, you can use any text. Blogger, on the other hand, has some unique macro include names: main-column-left-sections or main-column-right-sections (must be combined) or footer-sections, which are used for Blogger Template Designer Layout.

Below is the example code of those special macro includes:

<aside id='sidebar-left'>
 <macro:include id='main-column-left-sections' name='sections'>
   <macro:param default='0' name='num' value='0'/>
    <macro:param default='sidebar-left' name='idPrefix'/>
    <macro:param default='sidebar' name='class'/>
    <macro:param default='true' name='includeBottom'/>
  </macro:include>
</aside>

<div id='main'>
 <b:section id='content'>
  <b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'/>
 </b:section>
</div>

<aside id='sidebar-right'>
 <macro:include id='main-column-right-sections' name='sections'>
  <macro:param default='2' name='num' value='1'/>
  <macro:param default='sidebar-right' name='idPrefix'/>
  <macro:param default='sidebar' name='class'/>
  <macro:param default='true' name='includeBottom'/>
 </macro:include>
</aside>

<footer id='footer'>
 <macro:include id='footer-sections' name='sections'>
  <macro:param default='2' name='num' value='1'/>
  <macro:param default='footer' name='idPrefix'/>
  <macro:param default='foot' name='class'/>
  <macro:param default='false' name='includeBottom'/>
 </macro:include>
</footer>

Macroeconomic Benefits

To begin, if you utilise a b:section within an HTML5 element in your template code, your template users will not see this part in their admin Layout page. As a result, you may utilise macros to output your sections anywhere you want without fear of losing anything in the admin dashboard.

Second, if you utilise the specific macro included mentioned above, your users will be able to alter their template layout dynamically. Of course, you'll have to put in more effort to ensure that your template works.