Skip to content

Miva Structures#


Structures in the Miva Template Language are foundational data objects designed for organizing and managing hierarchical data. Similar to record or struct types in other programming languages, Miva structures encapsulate related data elements within individual fields, making them a powerful tool for developers to work with complex datasets.

By using structures, developers can efficiently manage data such as store settings, page details, and other relevant information, all accessible within the Miva Merchant environment.


Key Concepts of Miva Structures#

What is a Structure?#

A structure is a container that groups related data fields together. Each field in a structure can hold a specific data type, such as:

  • Strings
  • Integers
  • Arrays
  • Nested structures

This hierarchical organization allows for cleaner and more readable templates, as data can be logically grouped and accessed via a structured path.


The l.settings Structure#

One of the most important structures in Miva is the l.settings structure. It serves as a repository for variables that are automatically initialized and made accessible when a page loads. Module developers often use l.settings to expose variables for use within templates.

Key Features of l.settings:#

  1. Automatic Initialization: Upon page load, the l.settings structure is populated with relevant variables specific to the current page and store context.

  2. Global Accessibility: Variables in l.settings can be accessed anywhere within the page template without the &mvt: prefix typically required for global variables.

  3. Modular Flexibility: Developers can add custom variables to l.settings, allowing modules to seamlessly pass data to page templates.


Example Structure: l.settings#

The l.settings structure can contain multiple nested members. For example:

  • store: Contains variables related to the store’s settings, such as:

    • code: Store code
    • city: Store’s city
    • currency: Active currency
    • phone: Contact phone number
  • page: Includes details about the currently rendered page, such as:

    • code: Page code
    • id: Page ID
    • name: Page name

Visualization Example:

<!-- Accessing variables in l.settings -->
<p>Store Code: &mvt:store:code;</p>
<p>Store City: &mvt:store:city;</p>
<p>Page Name: &mvt:page:name;</p>


Conditional Evaluation of Variables#

To conditionally evaluate variables within the l.settings structure, use their full path. For example:

<mvt:if expr="l.settings:store:currency EQ 'USD'">
    <p>Transactions are processed in US Dollars.</p>
<mvt:else>
    <p>Transactions are processed in another currency.</p>
</mvt:if>

This ensures accurate referencing and comparison of variables in templates.


Best Practices for Using Miva Structures#

  1. Consistent Referencing: Always use the full path when accessing or evaluating variables to avoid ambiguity and ensure clarity.

  2. Logical Grouping: Take advantage of structures to group related variables, improving the readability and maintainability of your templates.

  3. Leverage Initialization: Use l.settings to expose custom variables from modules, ensuring data is readily available to templates.

  4. Avoid Redundant Variables: Use existing variables in l.settings wherever possible to minimize duplication and keep templates efficient.


Why Miva Structures Are Essential#

Understanding and effectively using Miva structures is crucial for creating robust and scalable templates. By mastering structures like l.settings, developers can:

  • Simplify data management in templates
  • Enhance template readability
  • Ensure data consistency across the store

What’s Next: Entities and Encoding#

While structures help you manage and organize your data, ensuring that this data is properly formatted and displayed in templates is equally important. This brings us to the concept of Entities and Encoding. Proper handling of special characters, encoded entities, and data output ensures your templates are secure, user-friendly, and error-free.

Next Topic: Entities and Encoding →

Dive into the next section to learn how Miva handles encoding and how you can use it to manage special characters and secure your templates.