Developer forum

Forum » Development » Render an Item?

Render an Item?

Aki Ruuskanen
Reply

Im trying to render an item in a paragraph razor template.

I get the item with:

Dynamicweb.Content.Items.Item item = Dynamicweb.Content.Items.ItemManager.Storage.GetById("Standard_Content", "1");

Then I tried this:

@RenderItem(item);

That results in a:

System.Reflection.TargetParameterCountException: Parameter count mismatch.

 

I also tried to this:

 

Dynamicweb.Content.Items.Rendering.Renderer r = new Dynamicweb.Content.Items.Rendering.Renderer();
Dynamicweb.Rendering.Template t = new Dynamicweb.Rendering.Template("ShowItem/Content.cshtml");
Dynamicweb.Content.Items.Item i = Dynamicweb.Content.Items.ItemManager.Storage.GetById("Standard_Content", "1");
r.RenderItem(i, t);
System.Web.HttpContext.Current.Response.Write(t.Output());

No errors but no output either. 

Any suggestions?

 

Regards / Aki

 

 

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

I really think you should use the item publisher...

Ot use ther template item render tag extension methods:

http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Module-tags/Item-publisher/Item-Render.aspx

 
Aki Ruuskanen
Reply

Thanks for the reply.

I have a number of ItemLists with a bunch of items and would like to be able to to render choses items from those lists in other parts of the sajt (like global elements). 

So I would like to render a specified Item with code. Is that not possible?

 
Nicolai Høeg Pedersen
Reply

Hi Aki, yes it is - see example 6 in the above link.

 
Aki Ruuskanen
Reply

Isn't that something that needs to be used with the ItemPublisher module?

 

 
Nicolai Høeg Pedersen
Reply

HI Aki

If you took 10 seconds to read the page, it would help a lot... smiley

"The Item publisher extension tag is a method to render an item directly in a template without the use of a page or paragraph."

Nicolai

 
Aki Ruuskanen
Reply

Is this extension tag available in the Razor templates? All the examples are for the "old" template stuff.

I have read the whole page. :)

 
Nicolai Høeg Pedersen
Reply

You could give it a go and see what happens...

 
Mikkel Ricky
Reply
This post has been marked as an answer

Have you read the Dynamicweb 8.4.1 release notes?

 

Votes for this answer: 1
 
Aki Ruuskanen
Reply

Well that release was almost a year ago so not lately. I usually don't read through all the release notes when trying to find information about some feature. Maybe that is something that should go in the documentation?  

Thanks for finding the answer to my question though. 

 

 
Nicolai Høeg Pedersen
Reply

I've added it to the docs!

 

You must be logged in to post in the forum