At runtime I need a way to exclude specific paragraphs from being rendered on a page.
Is there a notification I can use?
Regards,
Thomas
Developer forum
E-mail notifications
Exclude paragraphs
Posted on 07/02/2011 12:02:19
Replies
Posted on 07/02/2011 12:09:38
Hi Thomas,
There is a notification for paragraphs you can use.
Here is an example (not tested)...
[Subscribe(Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRender)]
public class ParagraphBeforeRender : NotificationSubscriber
{
public override void OnNotify(string notification, NotificationArgs args)
{
var parameters = args as Dynamicweb.Notifications.Standard.Paragraph.ParagraphNotificationArgs;
if (parameters == null) return;
var paragraph = parameters.Target;
paragraph.ShowParagraph = false; // add your own logic here
}
} You can also control what paragraphs are displayed by setting user permissions on those paragraphs, but that is probably not what you need.
BR.
Morten
Posted on 07/02/2011 13:51:58
Hi Morten,
Tanks for your reply, but unfortunately the code does not work
Tanks for your reply, but unfortunately the code does not work
var parameters = args as Dynamicweb.Notifications.Standard.Paragraph.ParagraphNotificationArgs;
Always return null
I have tried cast to Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs instead and this work.
var onBeforeRenderParameters = args as Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs;
But setting
onBeforeRenderParameters.Paragraph.Paragraph.ParagraphShowParagraph = false;
Don't change anything :-(
/Thomas
Always return null
I have tried cast to Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs instead and this work.
var onBeforeRenderParameters = args as Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRenderArgs;
But setting
onBeforeRenderParameters.Paragraph.Paragraph.ParagraphShowParagraph = false;
Don't change anything :-(
/Thomas
Nicolai Høeg Pedersen
Posted on 07/02/2011 14:27:22
Hi Thomas
The notification is raised just before each paragraph is rendered. Setting ShowParagraph to false does nothing at this stage.
But - you also have a template object as a parameter on the notification args. Set the html property of the template object to string.empty and nothing will be rendered.
The notification is raised just before each paragraph is rendered. Setting ShowParagraph to false does nothing at this stage.
But - you also have a template object as a parameter on the notification args. Set the html property of the template object to string.empty and nothing will be rendered.
Posted on 07/02/2011 14:58:27
Hi Nicolai,
This works, no output is generated from the paragraph then setting html to string.empty.
But then paragraph/module is still being "executed", and I would prefer not to use unnecessary resources on this.
A notification before the WriteParagraph method, would be a nice feature.
This works, no output is generated from the paragraph then setting html to string.empty.
But then paragraph/module is still being "executed", and I would prefer not to use unnecessary resources on this.
A notification before the WriteParagraph method, would be a nice feature.
Nicolai Høeg Pedersen
Posted on 07/02/2011 19:37:52
Hi Thomas
You can avoid the module from being executed by setting paragraphmodulesystemname to string.empty as well. That will have an impact on the module because module output is not generated untill the render of the paragraph. It is only active and publication period you cannot set on this notification subscriber because they are already checked for when getting the data.
Will look into further notifications.
You can avoid the module from being executed by setting paragraphmodulesystemname to string.empty as well. That will have an impact on the module because module output is not generated untill the render of the paragraph. It is only active and publication period you cannot set on this notification subscriber because they are already checked for when getting the data.
Will look into further notifications.
You must be logged in to post in the forum