Post by bhy » Mon Oct 07, 2019 8:27 pm

Hello,
I'm trying to display a flag of a country on product page on the condition that the name of an attribute starts with the name of that country.
Based on viewtopic.php?t=200460 I added the following to my product.twig to the column which has manufacturer, price etc.:

Code: Select all

{% if attribute_groups %}
            {% for attribute_group in product.attribute_groups %}
            {% for attribute in attribute_group.attribute %}
            {% if attribute.name starts with 'Čes' %}
            <li><img src="./image/czech_flag.png" alt="Český výrobek" title="Český výrobek" /></li>
            {% endif %}
            {% endfor %}
            {% endfor %}
{% endif %}
This does nothing. When I remove the for loops and the attribute name condition, the flag image is displayed correctly, so the problem must be in the loops and/or the condition. The above mentioned thread also describes some additions to the controller, but as far as I understand it, those are necessary only when this is put in category.twig, but for product.twig the required functionality is already available.

What am I doing wrong? Thank you very much.
Petr Břeň

bhy
New member

Posts

Joined
Fri Jul 17, 2015 7:28 pm

Post by paulfeakins » Tue Oct 08, 2019 5:11 pm

bhy wrote:
Mon Oct 07, 2019 8:27 pm
What am I doing wrong? Thank you very much.
I'm guessing the problem is this character "Č".

Try again using just "C" and that will confirm or deny this theory, then you can see what to do about it.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by bhy » Tue Oct 08, 2019 8:09 pm

paulfeakins wrote:
Tue Oct 08, 2019 5:11 pm
I'm guessing the problem is this character "Č".

Try again using just "C" and that will confirm or deny this theory, then you can see what to do about it.
Thank you. I changed the specification to CZE (and also tried changing the "starts with" to just 'C') and unfortunately the problem persists.

bhy
New member

Posts

Joined
Fri Jul 17, 2015 7:28 pm

Post by paulfeakins » Tue Oct 08, 2019 10:20 pm

So when you output "attribute.name" what do you get?

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by bhy » Wed Oct 09, 2019 7:28 pm

paulfeakins wrote:
Tue Oct 08, 2019 10:20 pm
So when you output "attribute.name" what do you get?
Strangely enough, <li>{{ attribute.name }}</li> doesn't output anything (or to be more precise, it outputs <li> </li>) and neither does attribute_name or just attribute.

bhy
New member

Posts

Joined
Fri Jul 17, 2015 7:28 pm

Post by bhy » Wed Oct 09, 2019 8:01 pm

Eureka! I looked to the part of product.twig that generates the specifications table next to the product description. If it works there, I must be able to reproduce it. So, the error was in the first loop. Instead of "product.attribute_groups" it should be just "attribute_groups". Probably because the controller already makes this available to the product page. The following works:

Code: Select all

{% if attribute_groups %}
            {% for attribute_group in attribute_groups %}
            {% for attribute in attribute_group.attribute %}
            {% if attribute.name starts with 'Fra' %}
            <li><img src="./image/french_flag.png" alt="Francouzské víno" title="Francouzské víno" /></li>
            {% endif %}
            {% endfor %}
            {% endfor %}
{% endif %}
Thank you very much and have a nice day!

bhy
New member

Posts

Joined
Fri Jul 17, 2015 7:28 pm

Post by paulfeakins » Thu Oct 10, 2019 5:01 pm

bhy wrote:
Wed Oct 09, 2019 7:28 pm
Strangely enough, <li>{{ attribute.name }}</li> doesn't output anything
Ah so that's why it didn't work, glad I could help :)

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom
Who is online

Users browsing this forum: No registered users and 14 guests