Developer forum

Forum » CMS - Standard features » ItemPublisher output ParagraphID

ItemPublisher output ParagraphID

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a situation where I need to create some Anchors.

I have managed to adjust the template to include the ParagraphID in the ID of the div and now I need to create a list of anchors.

In my setup, I am using the Swift_SectionHeader Itemtype for the anchors and I am trying to list the anchors using ItemPublisher.

The problem I have is getting the ParagraphID from the ItemPublisher for every Item in the list. I am using the old-fashioned TemplateTags for this purpose and none of the tags is rendering the ParagraphID.

Is there a better approach?

Thank you,
Adrian


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Anybody?

Thank you,
Adrian

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

I'm not sure what you are looking for.

If you want the id of the paragraph with ItemPublisher which is currently being rendered then you can use this:

int? paragraphId = Dynamicweb.Frontend.PageView.Current()?.CurrentParagraph?.ID;

If you want the paragraph id associated with each item then you can use this:

int? paragraphId = Dynamicweb.Content.Services.Paragraphs.GetParagraphForItem("YourItemType", "YourItemId")?.ID;

... and similar for pages:

int? pageId = Dynamicweb.Content.Services.Pages.GetPageForItem("YourItemType", "YourItemId")?.ID;
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,

Thank you very much for the suggestions.

In my case, I am using an ItemPublisher that exposes a list of Paragraphs:

@{
    var list = GetLoop("ItemPublisher:Items.List");
}

In this list, I need to get a hold of the ParagraphID.

@foreach(var anchor in list)
{
  //here I need the ParagraphID
}

I know exactly the ItemType but apparently the ItemID is not rendered in the list of available tags:

I am not sure if this is by design or some bug preventing the display of these values. Both the ParagraphID and the ItemID would be very helpful in the list of properties.

I can probably hack it by cleaning the ItemPublisher:Item.DetailsUrl value: /Default.aspx?ID=31533&itemId=Swift_SectionHeader:49
And in this case I can use your suggestion:

int? paragraphId = Dynamicweb.Content.Services.Paragraphs.GetParagraphForItem("Swift_SectionHeader", "49")?.ID;
 

Is there any other way of using the output of the ItemPublisher module? Maybe a ViewModel?

Thank you,
Adrian

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,

Apparently there is a tag that outputs the ID of the ItemType: ItemPublisher:Item.Field.Id

A bit confusing but still helpful.

My question about the ViewModel is still valid.

Thank you,

Adrian

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

ItemPublisher doesn't support view models yet.
We already have the view models for items, but they are just not used for rendering in ItemPublisher.
I think we could easily add them in DW10 - or provide a new module which is view model based. But there are currently no plans for this AFAIK.

/Morten

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,

Thank you for the confirmation.

I have managed to use your suggestion.

Thank you,
Adrian

 

You must be logged in to post in the forum