Try our new AI assistant by clicking the chat icon in the lower right corner.
Miva 10.03.00 introduces two new headers that can be passed into any http request to a Miva page which allow you to get back only the part of the page you need/want as either HTML or JSON. This gives you the flexibility and because the content can be returned as JSON it will support more advanced JavaScript functionality on the page.
Some use cases include:
The X-Partial-Render header tells Miva which part of the page you want returned. It values will be a single item code or list of items codes which assigned to the page you’re requesting.
Optionally you can specify an md5 hash of any param values you want to include in the item request. The most common use case for this will be requesting a ReadyTheme item such as a content section:
<mvt:item name="readytheme" param="contentsection( 'mini_basket' )" />
To request this item you would pass readytheme:24a308d4d1c2fc38a620b980f182a9f2 as the header where 24a308d4d1c2fc38a620b980f182a9f2 is the md5 hash of 'contentsection( 'mini_basket' )'
Only items that have a template output will return any response. For example, if you request the “store” item since it does not have an output template, nothing will be returned.
The X-Partial-Render-Output header is optional and defines the output format and content-type of the response.
There are two possible values: raw or json
If you set the render output as json the response will look like this:
The param_hash is always returned even if there was no parameter passed in the request
One of the most common use cases for this feature will be to request the basket or mini basket when some action occurs on the page. For example if you added a product to the cart via JavaScript/AJAX and now you want to reload the mini basket, you could make a request to any page with the mini basket assigned and get back the template as JSON or HTML. From here you could update the content on the page as you need.
If you are getting the response back as raw/html the response will be in the order you request each item.
When building advanced user interface experiences or even building a native mobile app its useful to be able to pull list of products assigned to a category. This can easily be done by requesting that category and the category_listing item. You can even get facets generated by Miva if you need facet data.
Some sites will want to display a modal of the product listing. You can leverage the same template that already exists on PROD and just call it in and display it in a modal on the category page. This gives you a single location to make layout changes without having to maintain code in multiple places.
One of the most powerful aspects of this feature is the ability to create your own JSON output to use in your user experience. Let say you wanted a list of all categories output in JSON. You could just request the category_tree item but this will have the full html template. Instead, we can create a custom page, assign the content component and output anything we want.
Here is an example:
To see a list of any available item for any page, navigate to the page under User Interface -> Templates then click the item tab and sort by assigned items. These are all the possible values for a given page which can be requested using the X-Partial-Render header