Developer forum

Forum » Templates » RenderItem() and RenderItemList()

RenderItem() and RenderItemList()

Kevin O'Driscoll
Reply
https://doc.dynamicweb.com/documentation-8/content/items/item-publisher#sideNavTitle1-2-2
https://doc.dynamicweb.com/template-tags/content/item-publisher/details#ItemPublisher:Item.DetailsUrl
 
I'm having problems with these extension methods. I understand I can render a single ItemType or a list of ItemTypes on any template in any page in my site.
I have 2 questions:
I have an ItemPublisher on a single page containing 30 or 40 paragraph Itemtypes.This works fine I can publish all with correct links to their details template etc.
 
Now I want to render a single chosen ItemType in the footer of all pages:
@RenderItem(new
        {
            ItemType = "Case_Study",
            SourceItemEntry = 408,
            ItemFields = "*",
            DetailsTemplate = "ItemPublisher/Details/Case Study Details.cshtml"
        })
This works fine (using the same details template for testing) until I want to use the hyperlink rendered from the standard template tags:
@GetValue("ItemPublisher:Item.Url") or @GetValue("ItemPublisher:Item.DetailsUrl")
If this is rendered in an <a href="@GetValue("ItemPublisher:Item.DetailsUrl")" I get a url like http://mysolution.com/en-us/home/thecasestudy-more--schwedt or
http://mysolution.com/en-us/about-us/thecasestudy-more--schwedt.
 
But what I really need is a url back to the details template where the ItemType paragraph lives: http://mysolution.com/en-us/case-studies/thecasestudy-more--schwedt. 
This URL pasted in the browser works well.
 
If I do <p>@GetValue("ItemPublisher:Item.Url")</p> I get the output: /Default.aspx?ID=1&itemId=Case_Study:408
I even tried @Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(GetString("ItemPublisher:Item.Url")) which dosnt work *Default.aspx?ID=1*
 
Secondly these dont work at all, is there something simple/obvious I'm missing here:
 
 string DataFromItem = RenderItemList(new
    {
        ItemType = "Case_Study",
        ListSourceType = "Page",
        ListSourcePage = "62",
        ItemFieldsList = "*",
        ListTemplate = "ItemPublisher/List/Case Study List.cshtml",
        ListPageSize = "100"
    }).ToString();
 
 @DataFromItem
 
@RenderItemList(new
        {
            ItemType = "Case_Study",
            ListSourceType = "ItemEntries",
            //ListSourceArea = 1,
            IncludeParagraphItems = true,
            ListSourcePage = 62,
            ItemFieldsList = "*",
            ListTemplate = "ItemPublisher/List/Case Study List.cshtml",
            ListPageSize = 100,
            ListOrderBy = "Study_Created_Date",
            ListOrderByDirection = "Descending"
        })
Any pointers would be appreciated.

Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Kevin,

 

RenderItem

Are you using Items as Pages or Items as Paragraphs? If you have always teh same DW page you can build your URL pointing to a hardcoded page ID or to a navigation tag

Something like this:

var url = "Default.aspx?Id=" + GetPageIdByNavigationTag("MyNavigationTagForMyItems") + "&ItemId=" + GetString("ItemPublisher:Item.ID");

This should give you the necessary url (I typed the tag, please confirm)
And the GetFriendlyUrl method does not work if you have a '/' charater, so you need to start with 'Default.aspx'

 

RenderItemList

You have mixes concepts there. Are you trying to get all Items from a specific source or specific items?

I believe what you're looking for is this

@RenderItemList(new
    {
        ItemType = "Case_Study",
        ListSourceType = "Page",
        ListSourcePage = 62,
        ItemFieldsList = "*",
        ListTemplate = "ItemPublisher/List/Case Study List.cshtml",
        ListPageSize = "100"
    })

 

(I took your first example and rendered it immediately (not assigning it to a variable) and made ListSourcePage an integer (not a string).

 

Hope this helps,

Nuno Aguiar

 
Kevin O'Driscoll
Reply

Hi Nino, thanks for this. Items as Paragraphs, I want all [Paragraph] Items of type "Case_Study" that are on PageID=62 Ordered by created date.

I dont have this method: Line 1076: The name 'GetPageIdByNavigationTag' does not exist in the current context. What Namespace is this in or is it your own? I have a similar utility method that does somthing like this: 

Dynamicweb.Content.Page page = Dynamicweb.Content.Page.GetPagesByAreaID(areaId).Where(n => n.NavigationTag == PageTagName).FirstOrDefault();

But it seems a shame we have to leap through these hoops when in the RenderItemList we actually supply the ListSourcePage = 62 

So your adaption of my version of @RenderItemList does not work for me nothing is rendered. Is there something that needs to be done in the list template (Im using the current List template I use in the Item Publisher module)??

My DW version is 8.9.2.6

 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Kevin,

 

RenderItem

>>  dont have this method: Line 1076: The name 'GetPageIdByNavigationTag' does not exist in the current context

Right, that's an issue. You can simply supply "62". That will make it hardcoded. You can also try to get it from a area setting (item as website properties for example), which is a lot simpler than Dynamicweb.Content.Page page = Dynamicweb.Content.Page.GetPagesByAreaID(areaId).Where(n => n.NavigationTag == PageTagName).FirstOrDefault(); and it's still make it dynamic.

 

RenderItemList

If your items are paragraphs, try adding the last parameter in bold underline below.

@RenderItemList(new
    {
        ItemType = "Case_Study",
        ListSourceType = "Page",
        ListSourcePage = 62,
        ItemFieldsList = "*",
        ListTemplate = "ItemPublisher/List/Case Study List.cshtml",
        ListPageSize = "100",
        IncludeParagraphItems = true
    })

 

I don't know if there's anything wrong in the list template. I'd have to see it too. One thing you can do is add @TemplateTags() on the (list) template to ensure you get the expected number of loop items and other expected tags. If you are getting no results in the templates, it means there's something wrong with the settings above. If you are getting results but they are not displaying, then the issue with related to the template itself.

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum