Skip to content

<mvt:do>#


The <mvt:do> tag in Miva Merchant’s template language is a versatile tool that provides direct access to call native MivaScript functions within compiled .mvc files (Miva LSK). This functionality enables developers to interact with the core Miva system and utilize its built-in libraries for tasks such as sending emails, managing cookies, rendering templates, and more.

Available on any page without requiring item assignments, <mvt:do> significantly extends the capabilities of Miva templates.

Empresa Requirement

Requires Miva Empresa Engine 5.22 or higher.


Syntax#

<mvt:do file="path_to_library" name="variable_name" value="FunctionName(parameters)" />

Parameters#

Parameter Description
file Required. Path to the compiled .mvc file relative to the mm5 directory. Can use predefined global variables for paths.
name Required. Name of the variable to store the function’s return value.
value Required. Name of the function to execute, along with its parameters.

Miva Library Variables#

Below are commonly used library variables with their respective paths:

Variable Path
g.module_library_billing_db /mm5/5.00/lib/mbs.mvc
g.module_library_utilities /mm5/5.00/lib/util.mvc
g.module_library_crypto /mm5/5.00/lib/crypto.mvc
g.module_library_db /mm5/5.00/lib/db.mvc
g.module_library_dbapi /mm5/5.00/lib/dbapi.mvc
g.module_library_native_dbapi /mm5/5.00/lib/dbapi_mysql.mvc

Examples#

Send an Email#

Send an email using the SendEmail function.

<mvt:assign name="g.to_email" value="'recipient@example.com'" />
<mvt:assign name="g.from_email" value="'sender@example.com'" />
<mvt:assign name="g.subject" value="'Hello from Miva!'" />
<mvt:assign name="g.message" value="'This is a test email.'" />

<mvt:do file="g.module_library_utilities" name="g.email_sent" value="SendEmail(g.to_email, g.from_email, '', g.subject, '', g.message)" />

<p>Email Sent: &mvt:global:email_sent;</p>

Validate Email Address Format#

Validate the format of an email address.

<mvt:assign name="g.email" value="'test@example.com'" />
<mvt:do file="g.module_library_utilities" name="g.is_valid" value="IsValidEmail(g.email)" />

<p>Email is Valid: &mvt:global:is_valid;</p>

Set a cookie and output it to the browser.

<mvt:assign name="g.cookie_value" value="'123456789'" />
<mvt:assign name="g.domain" value="'.example.com'" />
<mvt:assign name="g.path" value="'/'" />
<mvt:assign name="g.expires" value="'Wed, 21 Oct 2025 07:28:00 GMT'" />

<mvt:do file="g.module_library_utilities" name="g.null" value="SetCookie(g.Output_Cookies, 'session_token', g.cookie_value, g.domain, g.expires, g.path, 0)" />
<mvt:do file="g.module_library_utilities" name="g.null" value="OutputCookies(g.Output_Cookies)" />

Load a Product by Code#

Retrieve product details by its code.

<mvt:assign name="g.product_code" value="'ABC123'" />
<mvt:do name="l.return" file="g.module_library_db" value="Runtime_Product_Load_Code(g.product_code, l.product)" />

<p>Product Code: &mvt:product:code;</p>

Use With Caution

Runtime functions, such as Runtime_Product_Load_Code, can consume more server resources than their non-runtime counterparts because they account for factors like inventory availability, active pricing groups, and other runtime conditions. These functions are powerful but should be used judiciously to avoid performance issues, especially in loops or high-traffic areas.


Render a Page Template#

Render a specific page template by its code.

<mvt:do name="l.result" file="g.module_library_utilities" value="TemplateManager_Render_Page('ABUS')" />

Add a Customer to a Price Group#

Assign a customer to a specific price group if they are not already a member.

<mvt:if expr="g.Basket:cust_id GT 0">
    <mvt:do name="l.pricegroup_loaded" file="g.module_library_db" value="PriceGroup_Load_Name('SpecialGroup', l.pricegroup)" />

    <mvt:if expr="l.pricegroup_loaded EQ 1">
        <mvt:do name="l.exists" file="g.module_library_db" value="PriceGroupXCustomer_Load(l.pricegroup:id, g.Basket:cust_id, l.null)" />
        <mvt:if expr="NOT l.exists">
            <mvt:do name="l.inserted" file="g.module_library_db" value="PriceGroupXCustomer_Insert(l.pricegroup:id, g.Basket:cust_id)" />

            <p>Customer Added: <mvt:if expr="l.inserted">Success</mvt:if><mvt:else>Failed</mvt:else></p>
        </mvt:if>
    </mvt:if>
</mvt:if>

Best Practices#

  1. Understand Library Functions:

    • Familiarize yourself with available library functions in the Limited Source Kit (LSK) to maximize <mvt:do>’s potential.
  2. Secure Inputs:

    • Always validate input data, especially when interacting with customer or sensitive data.
  3. Leverage Return Values:

    • Use the name parameter to store and process return values effectively.
  4. Comment Your Code:

    • Document the purpose of complex <mvt:do> calls for better readability and maintainability.

Summary#

The <mvt:do> tag is a powerful tool for accessing native MivaScript functions, enabling developers to interact with the core system in dynamic and advanced ways. By leveraging built-in libraries and functions, you can extend your store’s functionality to meet unique requirements.

Key Takeaways:#

  • Use <mvt:do> to access core Miva functions directly.
  • Combine with library variables for powerful built-in utilities.
  • Always validate data and handle return values appropriately.