Developer forum

Forum » CMS - Standard features » Inherit Page content

Inherit Page content

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a situation where I have pages and subpages and I need to display in subpages content from parent page.

Not Page properties, but rather Paragraphs that are defined in a specific template area.

Is this possible with the API assuming I know the PageID of the page I try to inherit from?

Thanks,
Adrian


Replies

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

var pageService = ServiceLocator.Current.GetPageService();

var page = pageService.GetPage(pageId);

var parentPage = page.Parent;

Is this what you needed (razor-code)? If you want it for the template-tags, then no. I could not find anything that does what you ask for.

BR

Martin

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin,

Thank you very much for the response.

Almost :)

After getting the parent page, I need to display the content of a paragraph (or all paragraphs) that are assigned to the Intro Content section.

In the page template I would put a dwcontent div where I would assign paragraphs to. Those paragraphs I need to inherit in subpages.

What you showed me will get me the ParentPageID which is very helpful.. Now I need to render the content of the paragraphs of that page. preferably, the paragraphs that are defined in a specific template section. Probably I need another way of reading the paragraphs. Like GetParagraphID(PageID, ContentSection) then use something like RenderParagraphContent(ParagraphID).

What do you think?

Thanks,

Adrian

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

Alright, then I think we can expand the code a bit.

var pageService = ServiceLocator.Current.GetPageService();

var paragraphService = ServiceLocator.Current.GetParagraphService();

var page = pageService.GetPage(pageId);

var parentPageId = page.ParentId;

var paragraphs = paragraphService.GetParagraphsByPageId(parentPageId);

foreach(Paragraph paragraph om paragraphs) {

if(paragraph != correct) continue; //need to find a way to filter which paragaphs are needed;

var paragraphId = paragraph.Id;

//make html that needs to be rendered; fx. RenderParagraphContent(paragraphId);

}

In 9.2 this will cause a single DB-call to fetch the paragraphs. In 9.3 the paragraphs will be cached.

I'm unsure what exactly you need to do to filter for the correct paragraphs. Do you have an idea and can it be done via the exposed values on Paragraph?

BR

Martin

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin,

Thank you very much. This is very elaborated :)

First problem is that I am targeting DW8 because the solution in question is pretty old. However, I think there might be a DW8 equivalent to what you have suggested.

The second problem is how to determine the "correct" paragraphs.

I am thinking about defining the paragraphs in the ParentPage in the default content section and redirect the parent page to the first child.

This way I can render all paragraphs of the parent page since the page will never be rendered on its own.

How does it sound?

Thanks,

Adrian

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

Aah. Then I don't think you need to get the paragraphs. Just render the parent page, after you fetch it.

I don't know if this is going to be good or effective, but I cannot see any obvious errors in the way you present this. I would try to build it, and see if it works as intended.

Let me know what you come up with. :)

Btw. I see what you're trying to achieve: Shared properties across multiple pages. Can you elaborate a bit in relation to the actual use-case?

BR

Martin

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin,

Thank you for the feedback.

Basically, in my case, there are some details that are tied to an individual section. In our situation, the section is the parent page. The parent page will hold a paragraph with a short description (what this section is about) and a small slideshow with a few images. I have considered implementing these 2 types of content as separate paragraphs.

The section will have a few subpages, 4 or 5. But there might be cases where we can have more pages. And it becomes both difficult and uncontrolable to ask the admin to add always those paragraphs each time they create a new subpage.

I am pretty sure there are more useful scenarios for inheritance from parent pages. I remember I had a similar situation with inheritance of the Banner image from Parent page for all subpages in case the subpage did not had its own banner image. At that point, since it was just a property, I decided to use dwnavigation with a bit of XSLT to accomplish the task. The razor way, however is more friendly, but it would be helpful to have the eneitr logic wrapped in some methods/Helpers/Functions in order to accomplish it with less code in the template.

Thanks,

Adrian

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

Hmmm. Maybe it could be acomplished by using a layout that looks up a specific page and renders this page. The id of this page can then be saved somewhere as a custom property.

Would that solve your requirementns aswell?

BR

Martin

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin,

Too much configuration each time.

If this is handled in the template with a function like RenderInheritedContent(ParentPageID) it would be easier.

Of course, if this can be developed as a standard DW functionality, it would be a lot greater. But I imagine there will add a lot of complexity to the definitions. It can be easier with Page properties if they are defined to be inherited in the ItemType definition or in a separate config like the one used for Products (ManagementCenter/Ecommerce/Advanced/Fields)

But this will not handle inheritance of paragraphs unless the paragrah object has a property "inherit to child nodes".

Of course this all means Backend interfaces, template tags, so on and so forth. I would be happy to have this but I think there are more important functionalitites to be added before this one.

Thanks,
Adrian

 

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

Too much configuration each time? The placement of the custom property could be on website settings fx.? We sometimes use it when we have to configure "global" links, by inserting custom property linkpickers to the website settings page. Then it can be reused on multiple websites, where each website only needs to have each link configured once.

Anyway, I don't see DW9 as implementing inheritance for pages in the future - I also think we have more then enough really important issues, to get arround to this. : /

Please post when you have something up and running. I'm curious about how it'll end up. :)

BR

Martin

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin,

I believe I have misunderstood your suggestion. Configuring in the area section, will work if you always inherit the same things. Which should be the case in most situations. But if each section will have it's own characteristics, it's a bit more complicated.

I agree there are more critical issues than this one. I know I am waiting for a few :)

I will let you know after I implement it. Maybe it would be useful for other projects.

Thank you for all suggestions. They are very helpful.

Adrian

 

You must be logged in to post in the forum