Search Support
contact us

Let Us Make it Easy for You. Call 1-877-898-3290 for MyTime Support™. Learn More

Advanced Topics

Article Rating: 2 / 5 Votes: 27

nsScript

 

nsScript Introduction 

nsScript is an advanced feature that allows you to use dynamic variables and conditionals to customize certain aspects of your site.   In nsScript individual variables, conditionals, and sections are referred to as functions.  Basic uses of nsScript are explained below.

 

Operators 

Arithmetic Operators
 

+

Addition

Example: <% Product.ImageCount + 2 %>

-

Subtraction

Example: <% Product.ImageCount - 2 %>

*

Multiplication

Example: <% Product.ImageCount * 2 %>

/

Division

Example: <% Product.ImageCount / 2 %>

%

Modulus

Example: <ns:if condition “Product.ImageCount % 2 = 1"></ns:if>

 

 

Assignment Operators
 

=

Equals

 Example: <ns:if condition “Customer.Notes =’ ‘">

!=

Not Equal

 Example: <ns:if condition “Customer.Notes !=’ ‘">

||

Or

Example: <ns:if condition=" Product.HasOnSalePromo || Product.HasTaxFreePromo"></ns:if>       

&&

And

Example: <ns:if condition="Product.DisplayImageUrl != ‘ ‘ &&  Product.CustomerPrice > 10.00"></ns:if>

 

    

Conditionals

In addition to a section’s pre-defined Conditionals, any of that section’s values can be used in a conditional statement.  Below is an example using the customer notes value in the Invoice Design section.

Example:

<ns:if condition="Customer.Notes != ‘ ‘"><!-- do things -->

</ns:if>

 

The Choose statement can be used to create a more complex conditional. In ns:Script the Choose When/Otherwise block is used in place of the common If/Else statement.

Example:

<ns:choose>

<ns:when condition="Product.ImageCount > 1">View More Images</ns:when>

<ns:otherwise>View Larger Image</ns:otherwise>

</ns:choose>

 

Using JavaScript

nsScript can also be used within JavaScript.

Example:

<script type=”text/javascript”>

var prodId = <% Product.Id %>;

if (prodId = ‘120’){

document.getElementById(‘message’).innerHTML = “Hello World”;

}

</script>