Developer forum

Forum » Development » Get current Paragraph ID

Get current Paragraph ID

Diogo Lino
Reply
Hello,

How can I get the current paragraph ID in a custom module?

Thanks,
Diogo


Replies

 
Morten Snedker
Reply
This post has been marked as an answer
Hi Diogo,

That depends on the context? If it is a paragraph module it's just


using Dynamicweb;
using Dynamicweb.Extensibility;

namespace myShit
{
    [AddInName("ContentModule1")]
    public class ContentModule1 : ContentModule
    {
        public override string GetContent()
        {
            int pID = this.ParagraphId;

            //TODO: Add code here
            return "ContentModule1: frontend output";
        }
    }
}


Regards /Snedker
Votes for this answer: 0
 
Diogo Lino
Reply
Hi,

That's good for a ContentModule class.

The problem is when trying to get it from another class. There is a hard way by checking the paragraphs in the database and find a record where the ParagraphModuleSystemName is what I'm using and the ParagraphModuleSettings has the values I'm expecting. But it's not accurate.

Regards,
Diogo

 
Morten Bengtson
Reply
Hi Diogo,

What is this "another class"? You write that it is a custom module, but not a ContentModule... please explain :)

You could probably use a notification subscriber to get the current paragraph id - Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRender
You can then store the paragraph id in Request.Items and then get it from there in another notification subscriber, a template extender etc.

/Morten
 
Diogo Lino
Reply
In the ContentModule class I use several objects of diferent classes depending on the module properties to manage and return the content.

I can use the "this.ParagraphId" on the ContentModule class but in other classes where I already initialize them with the module properties and the pageView, I think the best solution is to initialize them also with the paragraphId as parameter or use notification subscribers as you say.

I though there could be a property on the pageView or other object that could help.

Thanks,
Diogo

 

You must be logged in to post in the forum