Developer forum

Forum » CMS - Standard features » RE: Items - List of pages with paragraphs and its content

RE: Items - List of pages with paragraphs and its content

Jan Sangill
Reply

Hi,

when using the itempublisher and using the "include section items" in a list of item pages.

What I want to do is list out the pages - which I can. But how do I get the content of the item paragraphs within that page?

 

Regards

Jan


Replies

 
Mikkel Ricky
Reply

The paragraphs on pages listed using the item publisher are not readily available (but you can get them using Razor).

Can you share some details on what you're trying to achieve? Maybe we can find another solution.

Best regards,
Mikkel

 
Jan Sangill
Reply

Hi Mikkel,

I am trying to list an XML feed of pages that fits a criteria.

If this criteria is met, then I need to have access to the page item, and its item paragraphs content.

Via razor would be perfect.

I would need access to the data from the item paragraphs as if I was extracting them via the itempublisher.

 
Jan Sangill
Reply

Hi Mikkel,

 

Did you have any idea on how to solve this instead?

 
Mikkel Ricky
Reply

Assuming your item paragraphs all have the same item type (Paragraph, say), you can generate an xml feed using three Razor templates each containing an inline item publisher (file paths relative to your design folder):

ForumThread_38149.cshtml (main layout template)

@* Prevent Dynamicweb from adding styles and scripts (e.g. analytics) @GetValue("Stylesheets")@GetValue("Javascripts")*@
@{ System.Web.HttpContext.Current.Response.ContentType = "application/xml"; }
<pages>
@RenderItemList(new {
	ItemType = "Page",
	ListSourceType = "Area",
	ListSourceArea = Pageview.AreaID,

	ItemFieldsList = "*",
	ListTemplate = "ItemPublisher/List/Pages.cshtml",
	ListPageSize = 100
})
</pages>
ForumThread_38149/ItemPublisher/List/Pages.cshtml
@if (GetBoolean("ItemPublisher:Items.Any")) {
	foreach (var item in GetLoop("ItemPublisher:Items.List")) {
		<page>
			<name>@item.GetValue("ItemPublisher:Item.Name")</name>
			<url>@item.GetValue("ItemPublisher:Item.Url")</url>
			…

			@RenderItemList(new {
				ItemType = "Paragraph",
				IncludeParagraphItems = true,
				ListSourceType = "Page",
				ListSourcePage = @item.GetInteger("ItemPublisher:Item.Field.PageId"),
				ItemFieldsList = "*",
				ListTemplate = "ItemPublisher/List/Paragraphs.cshtml",
				ListPageSize = 100
			})
		</page>
	}
}

ForumThread_38149/ItemPublisher/List/Paragraphs.cshtml

@if (GetBoolean("ItemPublisher:Items.Any")) {
	foreach (var item in GetLoop("ItemPublisher:Items.List")) {
		<paragraph>
			<name>@item.GetValue("ItemPublisher:Item.Name")</name>
			…
		</paragraph>
	}
}

I hope it makes sense and is useful (after some tweaking).

Best regards,
Mikkel

 
Jan Sangill
Reply

Hi Mikkel, Yes this makes sense.

 

TY for the input . WIll look into it.

 
Jan Sangill
Reply

On a sidenote:

Mikkel, is there any way of getting items via API somehow?  So it is not rendered, but returned to me?

And allso on very important thing.

This:

@{ System.Web.HttpContext.Current.Response.ContentType = "application/xml"; }

If this is placed inside a layout template, this causes errors on the page itself in the backend. I guess because it reads the files.

ALSO:

try {
    response.Clear();
    response.ContentType = "application/xml";
    response.Write(RenderXMLApp(new {
        Description = "",
        Ttl = 60
    }));
    response.End();
} catch {}

Will actually just output this in the backend.

Any WAYS to avoid the backend parser to get a hold of this?

 

 
Mikkel Ricky
Reply
This post has been marked as an answer

Wrap the header stuff in 

if (Dynamicweb.ExecutingContext.IsFrontEnd()) { … }

Check out Querying items and the item API documentation for information on how to get items using the Dynamicweb API.

Best regards,
Mikkel 

 

Votes for this answer: 1
 
Jan Sangill
Reply
EDIT2

made a query to db to get items from page, and then used the GetByID API call to get the items itself one by one.

 

You must be logged in to post in the forum