|
IntroductionOnline Module Builder Miva Script tags have the same form as HTML tags; the element names indicate their function and the attributes specify values that the tags operate on. They can be freely mixed with HTML tags or even embedded JavaScript. Along with tags, Miva Script provides a rich set operators and built in functions for string manipulation, math, file system, array manipulation, encryption, graphics and more. Example:<MIVA STANDARDOUTPUTLEVEL = "text, html, compresswhitespace"> <html> <head> <title>Discounted Price</title> </head> <body> <MvASSIGN NAME="g.price" VALUE="100.00"> <MvASSIGN NAME="g.discount" VALUE="0.20"> <p> <b>Discount Price: </b> $<MvEVAL EXPR = "{ (g.price - (g.price * g.discount)) ROUND 2 }"> </p> </body> </html> Miva Script file types.
Miva Script source files (filename.mv) are compiled then the compiled program upload to a web server using an ftp (File Transfer Protocol) program. When a browser requests a Miva Script document (filename.mvc), MivaMerchant Empresa executes the program passing the output to the browser for display. Alternatively you may use MivaMerchant Mia to run compiled scripts directly on your local computer and view them in a web browser. Writing a Miva Script ProgramWe recommend that you downloaded and installed Mia and the Compiler on your local machine so you can learn by and try the examples. You may also have access to a web server running Empresa and run can the script over the internet. Start Mia and take note of the WWW documents folder. Begin with the program example above, copy it into your favorite text editor (like notepad) and save it to that folder as discount.mv Open a dos window for the compiler and change to that folder. Type mvc discount.mvc press Enter. If successful nothing will happen otherwise an error message will be displayed. In Mia click the Home Page button to open your browser then in the address bar enter http://127.0.0.1:8001/discounts.mvc. You will see "Discount Price: $80.00" in the browser window. This simple program illustrates several important features of Miva Script programs:
Miva Script TagsLike HTML, all Miva Script tags consist of a start tag, such as <MvIF>, and some require end tag, such as </MvIF>. These are called closed tags. Tags like <EVAL> are called empty tags. Omitting a required closing tag or adding one to an empty tag will generate a compiler error. Example:<MvIF EXPR="{age GT 6}"> <MvEVAL EXPR="{age + 1}"> </MvIF> Nested closed tags must be balanced, that is, the innermost element's start- and end tags must both be between the outermost start- and end tags. Example:MvCOMMENT> Incorrect! </MvCOMMENT> <MvWHILE ..."> <MvIF ...> ... </MvWHILE> </MvIF> <MvCOMMENT> Correct! </MvCOMMENT> <MvWHILE ....> <MvIF...> ... </MvIF> </MvWHILE> Attributes, Literal Values and Expressions.Most tags contain attributes: these are names that are assigned a value surrounded by double-quotes. In this example NAME and VALUE are attributes, g.age is a variable assigned the value of 10. Attribute values must be surrounded by double quotes and may be expressed as literal values (text or numbers), as in the example above or as an expression. Expressions are always contained within curly braces. Literal string expressions are contained within single quotes. Example:<MvCOMMENT> Assign a literal value </MvCOMMENT> <MvASSIGN NAME="g.age" VALUE="10"> <MvCOMMENT> Assign an expression </MvCOMMENT> <MvASSIGN NAME="g.age" VALUE="{ 4 + 5 }"> <MvCOMMENT> Assign a string expression </MvCOMMENT> <MvASSIGN NAME="g.name" VALUE="{ g.prefix + 'Jon ' + 'Doe' }"> HTML ExpressionsA convenient feature of Miva Script is the ability to embed expressions inside HTML tag attribute values, or embed HTML inside Miva Script expressions. Example:<MvASSIGN NAME = "g.news" VALUE = "http://www.cnn.com"> <a href ="{ g.news }">Click Here </a> <input type="text" name="FirstName" value="{ g.FirstName }"> <MvASSIGN NAME="g.guestURL" VALUE= "<a href = '/guestbook'>Sign our Guestbook</a>" <MvEVAL EXPR = "{ g.guestURL }"> JavaScript with Miva ScriptJavaScript and Miva Script cannot interact directly, because the former is process by the browser and the latter is processed by the server. Miva Script programs execute, before the document gets to the browser. JavaScript runs in the browser after the page is received. However you can embed and even create JavaScript dynamically within your MivaScript program that will be executed by the browser using the HTML <SCRIPT> tag, just like any other html page.
|