Developer forum

Forum » Development » ItemPublisher with Product(s) in razor

ItemPublisher with Product(s) in razor

Harald Brouwers
Reply

Hello,

I have made an Itemtype consisting of the following field types: product, dropdownlist and file. But I can't get it working in my razor template. The code i'm using is:

@using Dynamicweb.Content.Items;
@using System.Web;

@{
    var request = HttpContext.Current.Request;
    var response = HttpContext.Current.Response;
    var items = GetLoop("ItemPublisher:Items.List");
    var pageTitle = @Pageview.Page.get_Value("PageMenuText");
}

<h2>On page "@pageTitle" I see @items.Count items</h2>
@foreach (LoopItem item in items)
{
    <table>
        @foreach (LoopItem field in item.GetLoop("ItemPublisher:Item.Fields"))
        {
            <tr>
                @field.TemplateTags()
            </tr>
        }
    </table>
}

The error occurs when I insert the line "@field.TemplateTags()", so this makes debugging for me very difficult because of the failing TemplateTags.
The error I'm getting is:

Exception in template (Designs\Pentair\eCom/Product/Product.cshtml): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.eCommerce.Frontend.Renderer.FixPathAndQuery(String PathAndQuery, String GroupID)
   at Dynamicweb.eCommerce.Frontend.Renderer.RenderProduct(Product Product, Boolean ExtendedProperties, Template Template, Int32 loopCounter, Boolean renderRelated, String productURL, Int32 quantity, Int32 wishListID, Boolean renderPublicList, Int32 orderLineOfProductCount)
   at Dynamicweb.Content.Items.Editors.ProductEditor.RenderProducts(EditorRenderingContext context)
   at Dynamicweb.Content.Items.Editors.ProductEditor.RenderValue(EditorRenderingContext context)
   at Dynamicweb.Content.Items.Rendering.Renderer.RenderValueInternal(Object value, Type valueType, Template template, String tagName, ItemField meta, Boolean tryRenderLinkedItem, ItemEntry itemEntry)
   at Dynamicweb.Content.Items.Rendering.Renderer.RenderItemField(ItemField field, Object value, Dictionary`2 validationErrors, Boolean allowEditing, Template template, String tagPrefix, ItemEntry itemEntry)
   at Dynamicweb.Content.Items.Rendering.Renderer.RenderItem(ItemEntry item, ItemSettings settings)
   at Dynamicweb.Content.Items.Rendering.Renderer.RenderItems(IEnumerable`1 items, ItemListSettings settings)
   at Dynamicweb.Modules.ItemPublisher.Frontend.List()
   at Dynamicweb.Modules.ItemPublisher.Frontend.GetContent()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Dynamicweb.Extensibility.AddInManager.InvokeFunction(Object instance, String FunctionName, Object[] Params)
   at Dynamicweb.Rendering.RazorTemplateBase`1.RenderItemList(Object settings)
   at CompiledRazorTemplates.Dynamic.eccbbbee.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()

What I want is to list / loop throug the item fields and working templatetags would be very welcome. Can somebody help me out?

Greetings Harald


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Can you try to disable the setting in customized URLs called UseCanonicalInEcommerce?

Votes for this answer: 1
 
Harald Brouwers
Reply
This post has been marked as an answer

Hi Nicolai,

I disabled the "Canonical link in meta" option, that solved the problem. I now have the expected output.

Thanks!

Votes for this answer: 1
 
Bjørn Kamfjord
Reply

BUMP!

I'm having the same issue, cant seem to get TemplateTags() to work when I try to put in a products loop?

I have tried turning on and off Canonical Link in meta, but no luck.

Any other solutions?

 
Nicolai Pedersen
Reply

Hi Bjørn

You should start another thread... Anyways - can you post your template code where you loop this and a dump of your item setup? And what happens - do you get exceptions, no data or what happens?

BR Nicolai

 
Bjørn Kamfjord
Reply

link to new thread

https://doc.dynamicweb.com/forum?ThreadID=56826&PID=1605

 

You must be logged in to post in the forum