Now up until this point we have seen a series of variables that look like what you see on the screen here. l.settings:product or &mvt:name. At first, these may seem foreign to you, but this is a core construct in Miva Merchant's core programming language Mivascript and also the template language. These are called Miva Merchant Structures. A structure is really just a collection of data with multiple elements under one name. So, l.settings is a structure. Within that structure it has a variable called product. Within that structure there's another one called code. So l.settings:product:code is a variable that references a product code. Let's take a look at an image that references a product code. Let's take a look at an image to help visualize this a little bit better.
So, a structure can contain another structure, or it can contain an actual variable. So here, we have l.settings. Within l.settings, there's two structures. There's a product structure and an attribute structure. Each structure, or level can be accessed through the colon. So l.settings is a local variable, then colon product references a product structure. Within that product structure there's three variables. There's code, name and price and the attribute structure has one called option. The Attribute option also has a structure and that has it's own price. So a structure can go multiple levels deep. Every level is accessed using colon and ultimately it will reference a variable. So l.settings:product:code references a product code. l.settings:attribute:price represents an attribute, an option and then the price for that option. So structures are a very common construct used in Miva Merchant and you'll see it all throughout the template language so it's an important concept to understand.
Let's take a look at some more examples. l.settings:store:code, so here we have an l.settings structure and within that it contains another structure called store and within that it has a variable called code. So that whole variable references the store code. You'll see l.settings used quite a bit, which we'll get into more quite a bit in the next video. However, a global variable can also be a structure. So here we have g.domain:address and g.colon:city. A domain is a structure, which right now has two variables; address and city.
One common question you might ask yourself when working with Miva Merchant structures is how do I visualize a structure? How do I see what data is contained in that structure? Well, there's a few ways. Let's take a look at a few examples. So here we have l.settings:store:code. So, l.settings is the structure, store is a structure and it looks like code is referencing the store code, so that looks like a variable. We also have l.settings:store:name and there could be other variables contained within l.settings:store. So really, the question is how do we know what other variables are contained within that store structure. It looks like it contains data about the store; the code, the name, possibly some other information. So I'm going to show you two easy ways to be able to visualize a structure, to see what data is contained in that structure. The first way to just to output that structure to the page. It's going to be exactly the same as you'd output any other variable. So it's going to be the &mvt:and then store. So here, if I was going to reference a code I would do :code and that's how I'll reference that specific variable. Let's say I don't want the code, I'm going to delete that and just put the semi color here. That's going to try and output the entire structure. Let's bring this over to Miva and see what happens. So here we're back at the Miva Merchant Admin. I'm going to come up to the search box here and I'm going to go to the storefront page. SFNT is the code. I'm going to go to the storefront contents section and here I'm going to paste in our code. We have this &mvt:store; which should output the entire store structure. Let's save this and see what happens. Now when I come back to the storefront and hit refresh, you'll see it outputs a lot of information and it looks like a comma separated list. So this will give you all the data this structure contains, but it's not in an easy to use format. But, at a high level you can see all the data that's contained in that source structure. So it looks like it has the address, has the name of the store, has some settings about the store; so all that is contained within the store structure. Well the next question you may have is , great I see the values contained in the structure, but how do I reference those values. How do I know if it's the store code, the store name, the store number. Well, let's take a look at one more example of how to visualize a structure.
The other way to output a structure to the page is to use a built in function of the Miva Merchant Engine called Miva Array Serialize. Now, if you're familiar with serialize and de-serialize in other programming languages, this is exactly the same. What it does is it takes an object, in this case we have a structure, and it outputs it to a format that can be saved into a database and later retrieved and you can deserialize it so you can convert it back to the original object that it was. So here, we're just going to use the serialized function to output this to the page. We're going to use the mvt eval tag. The function is miva_array_serialize and then we're passing in l.settings:store which is the store structure. So let's grab this and see what happens when we execute it. Back at my storefront page under the Content section, I'm going to remove the old code we have here and I'm going to replace it with this new code and hit save. So now when I come back and hit refresh, so you'll see this still isn't easy to read, but it has name value pairs. It shows :address and then it has the address, then baskexp which is the basket expiration time 60 minutes and it has a bunch of other settings about the store.; the city, the company, the country. So here you can actually look through this code and see what the name value pairs are. The name is what you would want to use when you're referencing that specific value from the structure. So if I wanted the address it would be &mvt:store:address. So both these tools are a great way to be able to quickly visualize what data is in the structure and how to access that data. There's actually a third way and it's much easier and doesn't involve outputting to the screen. Miva has a built in tool called Tokenlist, which takes all this information and organizes it into a very easy to use searchable and easy to read screen within the admin. Now we're going to save Tokenlist for another video, but I want you to know that it exist because it will it will be your go to resource when troubleshooting and trying to find things like this, what data is contained within the structure.