1 <tr>
2 {% for field in order.public_custom_fields_list %}
3 {% capture field_value %}{{field | custom_field_data: order.id}}{%endcapture%}
4 {% if field_value.size > 0 %}
5 <td>{{field.field_name}}: {{field_value}}</td>
6 {% endif %}
7 {% endfor %}
8 </tr>
Lines 1 and 8 define a row in a table.
Line 2 and 7 form a programmatic loop. For each loop the variable "field" is assigned one of the custom fields from the set defined for the "order".
Line 3 assigns the field's value to a variable called field_value.
Lines 4 and 5 form a programmatic block that will execute only if there is any content assigned to field_value. So, if field_value is blank, line 5 will not be executed; no table division will be created.
For example, if we defined custom fields of, say "FOB Point" and "Carrier" for our order, the above code could generate the following HTML:
<tr>
<td>FOB Point: Ex Works</td>
<td>Carrier: Cosco</td>
</tr>
If you only want a particular field, say 'FOB Point', to be displayed, then change line 4 to filter on the desired field as follows:
{% if field.field_name == 'FOB Point' and field_value.size > 0 %}
Comments and Suggestions
0 comments
Please sign in to leave a comment.
Related articles