Developer forum

Forum » Development » Get Paragraph Content

Get Paragraph Content

Yasharth Tahiliani
Reply

Hi, I am trying to get the content of a paragraph in the homepage of my website using the DynamicWeb.Content class.

I am trying to get this information in a Razor template so that I can display the content of a paragraph on the homepage on other pages using that template!

I am trying something like this:

                        <p class="bold">Before tour</p>
                        @{
                            Dynamicweb.Content.Paragraph para = Dynamicweb.Content.Paragraph.GetParagraphById(64);
                            string content = para.Text;                           
                         }
                        @content
                      </div>   

However, this is not displayed anything. I have checked that 64 is the ID of the paragraph in the Paragraph table in the database.

Can someone who might have done a similar thing please guide me with this?

Thanks and Regards,

Yash.


Replies

 
Rene Poulsen
Reply

Hi Yash,

Have you tried the renderparagraphcontent?

@RenderParagraphContent(64)

 
Nicolai Høeg Pedersen
Reply

@Dynamicweb.Content.Paragraph.GetParagraphById(64).Text will work if it is a regular paragraph and there is text in the text field. If it is an item type, the text field has no value and return nothing. So what René says is a better approach - that will render the entire paragraph using the template, module, item info etc.

 
Yasharth Tahiliani
Reply

Yes, you are right! It is because it is an item type.

I tried Rene's approach, and it works great! :) 

Thank you so much guys, really appreciate it!

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Solved it

here is how to do it

 


@{

var paraid=GetInteger("ItemPublisher:Global.ParagraphId");
ParagraphService P = new ParagraphService();
string paragraphHeader=P.GetParagraph(@paraid).Header;
}
<h1>@paragraphHeader</h1>
 

 

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

OOOPS, wrong thread - but my answer is still relevant :)

 

/Hans

 
Nicolai Pedersen
Reply

Nice - thanks for sharing!

 

You must be logged in to post in the forum