Post by torm1358 » Sat May 08, 2021 9:45 pm

Following learning how to use different templates for different products, I am now working on how to display the numerous options in a table rather than a list in one column. I though that using HTML table tags, i.e. <table>, <tr> and <td> etc would work, but it didn't. The code for the displaying the options is as follows:

{% set c = 1 %}
<div id="product"> {% if options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in options %}
{% if c == 2 %}
<table>
{% endif %}
{% if c == 2 or c == 6 or c == 8 or c == 12 %}
<tr>
{% endif %}
{% if C > 1 and C < 14 %}
<td>
{% endif %}
{% set c = c + 1 %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% if C > 2 and C < 15 %}
</td>
{% endif %}
{% if c == 6 or c == 8 or c == 12 or c == 14 %}
</tr>
{% endif %}
{% if c == 14 %}
</table>
{% endif %}
{% endfor %}

The way it is supposed to work is that the table is opened on option 2 with new rows started on options 2, 6, 8 and 12 and ending after options 5, 8, 12 and 14 and the table closed after option 14. However, for reason the options are not displayed in a table, and options 5, 7, 10 and 11 are incorrectly displayed. What have I done wrong and how do I correct this?

To see how it looks now, visit https://optics3d.co.uk/Accessories/p3dipolblack. To see how the table is supposed to look, visit http://www.optics3d.co.uk/RxMulti3D%20B ... asses.html.
Last edited by torm1358 on Thu May 13, 2021 7:47 am, edited 1 time in total.

New member

Posts

Joined
Tue Oct 11, 2016 11:03 pm

Post by straightlight » Sat May 08, 2021 9:59 pm

torm1358 wrote:
Sat May 08, 2021 9:45 pm
Following learning how to use different templates for different products, I am now working on how to display the numerous options in a table rather than a list in one column. I though that using HTML table tags, i.e. <table>, <tr> and <td> etc would work, but it didn't. The code for the displaying the options is as follows:

{% set c = 1 %}
<div id="product"> {% if options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in options %}
{% if c == 2 %}
<table>
{% endif %}
{% if c == 2 or c == 6 or c == 8 or c == 12 %}
<tr>
{% endif %}
{% if C > 1 and C < 14 %}
<td>
{% endif %}
{% set c = c + 1 %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% if C > 2 and C < 15 %}
</td>
{% endif %}
{% if c == 6 or c == 8 or c == 12 or c == 14 %}
</tr>
{% endif %}
{% if c == 14 %}
</table>
{% endif %}
{% endfor %}

The way it is supposed to work is that the table is opened on option 2 with new rows started on options 2, 6, 8 and 12 and ending after options 5, 8, 12 and 14 and the table closed after option 14. However, for reason the options are not displayed in a table, and options 5, 7, 10 and 11 are incorrectly displayed. What have I done wrong and how do I correct this?

To see how it looks now, visit https://optics3d.co.uk/Accessories/p3dipolblack. To see how the table is supposed to look, visit http://www.optics3d.co.uk/RxMulti3D%20B ... asses.html.
OC version. Custom codes request. However:
{% if C > 1 and C < 14 %}
{% if C > 2 and C < 15 %}
Using an uppercase C instead of a lowercase C. In the mean time, each modifications may require to clear cache if using an external editor. See this FAQ post: viewtopic.php?f=134&t=215776#p718325 . In addition, since tables in Opencart are using Bootstrap CSS, ensure to add those classes.

SEO URL structures of the posted link is also wrong; contains spaces in URL.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by torm1358 » Wed May 12, 2021 9:49 pm

Thank you for your helpful reply. In addition to the inconsistent type case of the counter, C, I had put the table end tags, i.e. the </td>, </tr> and </table> in the wrong place. These should have been placed further down starting from what was line 261. Now I have done this, the options that need to be in a table are so, and, in my opinion, looks much better.

New member

Posts

Joined
Tue Oct 11, 2016 11:03 pm

Post by straightlight » Wed May 12, 2021 9:51 pm

torm1358 wrote:
Wed May 12, 2021 9:49 pm
Thank you for your helpful reply. In addition to the inconsistent type case of the counter, C, I had put the table end tags, i.e. the </td>, </tr> and </table> in the wrong place. These should have been placed further down starting from what was line 261. Now I have done this, the options that need to be in a table are so, and, in my opinion, looks much better.
Now that the issue has been resolved, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: Google [Bot] and 97 guests