Developer forum

Forum » CMS - Standard features » Get Item by paragraph id

Get Item by paragraph id

Adrian Ursu
Reply

Hi Guys,

I am trying to get an Item in Razor using the SystemName and the paragraph ID but I cannot make it work.

I have used some of the information from here: http://developer.dynamicweb.com/documentation/for-developers/item-based-structure/querying-items.aspx

I tried: var paragraph = Dynamicweb.Content.Items.ItemManager.Storage.GetByParagraphId("StandardParagraph", paragraphID );

I get a nasty error:

Exception in template (Designs\NewDesign\ItemPublisher/List/JobList_Careers.cshtml): System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at Dynamicweb.Content.Items.Queries.Repository.SelectByParagraphId(IEnumerable`1 paragraphIds, Query query)
   at Dynamicweb.Content.Items.Queries.StorageManager.GetByParagraphId(String systemName, Int32 paragraphId)
   at CompiledRazorTemplates.Dynamic.edffeacfaeac.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.Output()

Any ideas?

Thanks,

Adrian


Replies

 
Nicolai Høeg Pedersen
Reply

Only that you are passing a systemname or paragraphid that does not exist.

When you have the paragraph, you have the item type and item id - use them like this instead: Items.ItemManager.Storage.GetById(ItemType, ItemId)

 
Adrian Ursu
Reply

Thanks Nicolai,

I don;t seem to be able to get the ItemID in the Item publisher List template.
The setup is this:

1. ItemType Paragraph

2. Item publisher module in the above paragraph

3. ItemPublisher List template will not list any attribute of the parent Paragraph except for the ParagraphID

The problem is that I need to access some attributes of the Paragraph that holds the ItemPublished. The same problem appears even if I use a normal paragraph instead of an ItemType Paragraph.

I have used TemplateTags to see what I can access.

Thanks,

Adrian

 

 
Nicolai Høeg Pedersen
Reply

If you have the paragraph id, get the paragraph

Content.Paragraph.GetParagraphById(id)

then use that instance that contains the itemtype and itemid to get hold of the item itself.

Beware of performance.

 
Nicolai Høeg Pedersen
Reply

You can actually access Pageview.CurrentParagraph and take the itemid and itemtype from that.

 
Adrian Ursu
Reply

Thanks a lot Nicolai.

It would be very helpful to know everything that can be accessed.

Can these Pageview values be included in the TemplateTags output?

 
Nicolai Høeg Pedersen
Reply

No they cannot. It is part of the API, and Visual Studio will show it to you if you set it up correctly.

You can also see what is available in the API docs: http://developer.dynamicweb.com/api8/

 
Adrian Ursu
Reply

Hi Nicolai,

I am not a visual Studio user. Not just yet :)

I will work on that.

Thank you,

Adrian

 

You must be logged in to post in the forum