Developer forum
E-mail notifications
Replace in paragraph
Lets say that every where on the page where there is written "secret" - it should be replace with "urgent".
How can this be done?
I've had a look into both the PageTemplateExtender and ContentModule with no luck.
Im not interessed in replacing it the actual database - only when it written to the client.
/Morten
Replies
You can use the Standard.Page.AfterOutput notification subscriber:
Imports Dynamicweb
Imports Dynamicweb.Frontend
Imports Dynamicweb.Extensibility
<Subscribe(Dynamicweb.Notifications.Standard.Page.AfterOutput)> _
Public Class NotificationSubscriber1
Inherits NotificationSubscriber
Public Overrides Sub OnNotify(ByVal notification As String, ByVal args As Object())
Dim t As Templatev2.Template = CType(args(0), Templatev2.Template)
t.Html = t.Html.Replace("Oldstring", "Newstring")
'TODO: Add code here
End Sub
End Class
With the newest SR (19.0.3.0) you will be able to use the
Standard.Paragraph.OnBeforeRenderArgs notification to access the ParagraphText field directly.
<Subscribe(Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRender)> _
Public Class NotificationSubscriber2
Inherits NotificationSubscriber
Public Overrides Sub OnNotify(ByVal notification As String, ByVal args As NotificationArgs)
Dim arg As Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs = CType(args, Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs)
If Not String.IsNullOrEmpty(arg.Paragraph.Paragraph.ParagraphText) Then
arg.Paragraph.Paragraph.ParagraphText = arg.Paragraph.Paragraph.ParagraphText.Replace("oldstring", "newstring")
End If
End Sub
End Class
DW FTW!
You must be logged in to post in the forum