API
The Dynamicweb API makes it possible to interact directly with various object types in Dynamicweb outside of the TemplateTag and ViewModel systems.
In general you should only use the API if you:
- Cannot accomplish what you want using normal means, i.e. via TemplateTags & ViewModels
- Know what you’re doing and that understand you can really screw your performance if you’re not careful
- Accept full responsibility for your own code
A typical usecase could be that you need to work with something for which there is no TemplateTag – like displaying the loyalty point balance of the current user in the shopping cart – or need to access a property on the product object which hasn’t been added to the ViewModel (like the product type).
To use the API you must usually go through one of the following classes:
- Dynamicweb.Services is used to work with non-Ecommerce-related content such as Pages, Items, Paragraphs, etc.
- Dynamicweb.Ecommerce.Services is used to work with Ecommerce-related content such as Products, Orders, Shops, etc.
- Dynamicweb.Security.UserManagement is used to work with users, user groups, addresses, etc.
Under each of these you will have access to other services - like the IPageService or the IAreaService - and/or system object (e.g. Dynamicweb.Security.UserManagement.User) and methods related to them (e.g. GetCurrentExtranetUser)
Since this is a website and not an IDE with code-hinting, any example I give here will be less than useful since you won’t be able to see important information about e.g. the parameters passed to the API, but still – here are a couple of examples: