Is it possible with custom code to add your own expression macros?
BR
Thomas
Developer forum
E-mail notifications
Index query expression macro
Replies
Yes, you just need to inherit Dynamicweb.Extensibility.Macros.Macro from Dynamicweb.Extensibility.dll
An example of one of our macros:
Imports Dynamicweb.Extensibility.Macros
Imports System.Collections.Generic
Namespace eCommerce.Common
Public Class ContextMacro
Inherits Macro
Private Shared ReadOnly SupportedActionsInternal As New Dictionary(Of String, Func(Of Object)) From
{
{"LanguageID", Function() Context.LanguageID},
{"ShopID", Function() Input.FormatString(Dynamicweb.Frontend.PageView.Current.Area.Value("AreaEcomShopID"))},
{"CartID", Function() If(Context.Cart IsNot Nothing, Context.Cart.ID, Nothing)}
}
Private Shared ReadOnly LockObject As New Object()
Public Overrides Function Evaluate(action As String) As Object
'Prepare return value
Dim value As Object = Nothing
SyncLock LockObject
'Make sure action is supported
If SupportedActionsInternal.ContainsKey(action) Then
Try
'Get value from action
value = SupportedActionsInternal(action)()
Catch ex As Exception
'Maybe log this?
End Try
End If
End SyncLock
'Return the value if one was found, otherwise Nothing
Return value
End Function
Public Overrides ReadOnly Property Name As String
Get
Return "Dynamicweb.Ecommerce.Context"
End Get
End Property
Public Overrides ReadOnly Property SupportedActions As IEnumerable(Of String)
Get
Dim result As IEnumerable(Of String)
SyncLock LockObject
result = SupportedActionsInternal.Keys.ToList()
End SyncLock
Return result
End Get
End Property
End Class
End Namespace
Thanks, just what i needed
You must be logged in to post in the forum