MivaScript: Getting Inside "Hello World"

Miva Merchant Modules and Development
This is where we look more closely at how MivaScript interacts with HTML and the browser. There are quite a few ways to display "Hello World" and each one is useful for different reasons.

MivaScript: Getting Inside "Hello World"

We're going to explore various ways to use MivaScript to display "Hello World".


This is where we look more closely at how MivaScript interacts with HTML and the browser. There are quite a few ways to display "Hello World" and each one is useful for different reasons.

by Scot Ranney • March 24, 2015

Miva Scripting 101


The MvEVAL tag is the way to display data to the browser window. (MivaScript docs)

In the last tutorial we installed the MivaScript environment and use MvEVAL to display 'Hello World!'

<MvEVAL EXPR = "{ 'Hello World!' }">

MvEVAL is used to display constants, variables, expressions, and most other data in MivaScript.

'Hello World!' is a constant and it's called that because it never changes. If you wanted to use a variable, such as the MivaScript system variable of s.dyn_time_t (number of seconds since 1 Jan. 1970) it would be displayed similarly to 'Hello World!' but without the single quotes.

<MvEVAL EXPR = "{ s.dyn_time_t }">

Use the $ symbol to concatenate variables (connect them together) and display them at once.

<MvEVAL EXPR = "{ 'It has been ' $ s.dyn_time_t $ ' seconds since time began in 1970.' }">

All constants, or string, are enclosed in single quotes, and they are attached to other variables using the $ symbol.

MivaScript can be mixed with HTML and the line above could also be coded like this:

It has been <MvEVAL EXPR = "{ s.dyn_time_t }"> seconds since time began in 1970.

You can mix it in with HTML and display it like this:

<p>
It has been <MvEVAL EXPR = "{ s.dyn_time_t }"> seconds since time began in 1970.
</p>

The HTML above could also be displayed like this:

<MvEVAL EXPR = "{ '<p> It has been ' $ s.dyn_time_t $ ' seconds since time began in 1970. </p>' }">

You can evaluate math using standard math rules:

<MvEVAL EXPR = "{ 4 + 7 }">

This would display 11 in the browser window.

<MvEVAL EXPR = "{ 4 + (3 * 2) - (6 / 3) }">

This displays 8 (algebra rules turns the above math into: 4 + 6 - 2)

Controlling The Display Output

MivaScript allows you to control the output level using the MIVA tag. It's a special tag that controls various display, error display, and other features in the MivaScript app. This display output control only works on the plain text in your MivaScript. Anything inside an MvEVAL tag will display regardless.

The most common use is the STANDARDOUTPUTLEVEL which controls what exactly you can display without using the MvEVAL tag. The basic everything goes output level is like this and would force the following code to display as-is:

<MIVA STANDARDOUTPUTLEVEL = "compresswhitespace,text,html">
<p>
It has been <MvEVAL EXPR = "{ s.dyn_time_t }"> seconds since time began in 1970.
</p>

The compresswhitespace switch doesn't affect what you see as much as what is behind the scenes. There are times when extra whitespace is generated and we want that suppressed to keep page load time to a minimum. Most of the time, extra whitespace is a result of how you coded your MivaScript app and as you get more experience this will be less of an issue.

If we used the text switch only, all you would see is: It has been seconds since time began in 1970.

Using the html switch will for only HTML to be displayed.


overall rating:
my rating: log in to rate

mivascript tutorial

The blog posts on Scot's Scripts are made using by Scot's Blogger, a full featured Wordpress replacement Miva Merchant blogging module.