Developer forum

Forum » Templates » Content only available when TemplateTag is present

Content only available when TemplateTag is present

Thomas Schroll
Reply

Hi

I have a weird problem in my product template. I'm trying to output the value of all custom fields by doing this:

                                @foreach (var CustomFieldElement in GetLoop("CustomFieldList")) {
                                    string loopname = CustomFieldElement.GetString("Ecom:CustomField.System");
                                    <tr>
                                        <td>@CustomFieldElement.GetString("Ecom:CustomField.Name"):</td>
                                        <td>
                                            @foreach (var CustomField in GetLoop(loopname + ".Options")) {
                                                if (CustomField.GetBoolean(loopname + ".Option.IsSelected")) {
                                                    @CustomField.GetString(loopname + ".Option.Name")<text>, </text>
                                                }
                                                @*@CustomField.TemplateTags()*@
                                            }
                                        </td>
                                    </tr>
                                }

I'm doing it this way because I need the field names, not values and I have too many custom fields to do it manually. This works, but if I remove @*@CustomField.TemplateTags()*@ nothing is outputted.

Does anybody how to remove the TemplateTag() and still show the content, or does somebody know a better way to output the content?

Regards Thomas


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Thomas

Dynamicweb checks if the template has a specific loop before it renders content to that loo. When you do like this: GetLoop(loopname + ".Options") you create the loopname dynamically, so the name of the loop is not in the template and there DW does not render it. When you add TemplateTags() it will render everything to display in the table. So that is why.

Consider using the CustomFields loop instead: http://templates.dynamicweb.com/eCommerce/Dynamicweb-eCommerce-template-tags/Product-Catalog/Product-detail/Loops/CustomFields.aspx

BR Nicolai

 
Thomas Schroll
Reply

Thanks Nicolai.

I can't use CustomFields loop instead because the fields are lists. The name and values of the lists are different and DW only output values where I should output names.

Also I would prefer not to hardcode all fields where I just need to output all fields.

I'll just have to go through all loops manually then.

Regards Thomas

 
Thomas Schroll
Reply

For anybody interested, I found a workaround:

If I include a helper in razor the fields get outputted:

                        @helper customFields(string loop) {
                            if (Loops.Contains(loop + ".Options")) {
                                foreach (var CustomField in GetLoop(loop + ".Options")) {
                                    if (CustomField.GetBoolean(loop + ".Option.IsSelected")) {
                                        @CustomField.GetString(loop + ".Option.Name")<text>, </text>
                                    }
                                }
                            }
}

                                @foreach (var CustomFieldElement in GetLoop("CustomFieldList")) {
                                string loopname = CustomFieldElement.GetString("Ecom:CustomField.System");
                                    <tr>
                                        <td>@GetString("Ecom:Product:Field."+loopname+".Name"):</td>
                                        <td>@customFields(loopname)</td>
                                    </tr>
                                }

Regards Thomas

 

 
Nicolai Høeg Pedersen
Reply

Great - thanks for sharing!

 

You must be logged in to post in the forum