new Meta()
Constructor for metadata singleton
This should be initialized via the current context object (product, category, asset or folder) and can be used to retrieve the page metadata, breadcrumbs and to render the accumulated information to the client
Methods
addResource(key, bundle, defaultValue)
Adds a resource key to meta, the key of the given bundle is simply dumped to a data attribute and can be consumed by the client.
Parameters:
Name | Type | Description |
---|---|---|
key |
string |
The resource key |
bundle |
string |
The bundle name |
defaultValue |
string |
Optional default value, empty string otherwise |
Example
// on the server
require('meta').addResource('some.message.key', 'bundlename');
// on the client
console.log(app.resources['some.message.key']);
getBreadcrumbs() → {Array}
Get the breadcrumbs for the current page
Returns:
an array containing the breadcrumb items
- Type
- Array
renderClientData() → {String}
Dumps the internally held data into teh DOM
Returns:
A div with a data attribute containing all data as JSON
- Type
- String
update(object)
The core method of this class which updates the internal data represenation with the given information
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | dw.catalog.Product | dw.catalog.Category | dw.content.Content | dw.content.Folder |
The object to update with |
Example
// using a product object
meta.update(product);
// using a plain object
meta.update({resources: {
'MY_RESOURCE': dw.web.Resource.msg('my.resource', 'mybundle', null)
}});
// using a string
meta.update('account.landing')
updatePageMetaData()
Update the Page Metadata with the current internal data