jan-vince / smallgdpr

OctoberCMS plugin to cope with GDPR
MIT License
9 stars 9 forks source link

Unexpected token "name" of value "if" ("end of statement block" expected). #22

Closed MateThemes closed 8 months ago

MateThemes commented 2 years ago

Hello! I have following error on the smallgdpr plugin

Unexpected token "name" of value "if" ("end of statement block" expected). ~/plugins/janvince/smallgdpr/components/partials/run-scripts.htm line 5 {% if cookiesSettingsGet('cookies',null)|length %}

{% for cookie in cookiesSettingsGet('cookies') %}

    {% for script in cookie.scripts if script.scripts_disable == 0 %}

        {#  If pages list is set, compare to current page URL #}

        {% if script.scripts_run_pages == true and script.scripts_run_pages_list|length %}

            {% set scriptRunThisPage = false %}

            {% for item in script.scripts_run_pages_list %}

`

jan-vince commented 2 years ago

Try update second line to this: {% for script in cookie.scripts %}

Just to check, i this is the cause of the error.

What version of October do you use?

MateThemes commented 2 years ago

I use October v3.

I changed the second line and now the banner works fine!

Thank you for your fast help!

jan-vince commented 2 years ago

But it is not a solution as this line is filtering disabled scripts.

I will test it in OC3 again as I do not use this version on production sites.

MateThemes commented 2 years ago

Thank you

MateThemes commented 2 years ago

What if you change the code to this:

` {% if cookiesSettingsGet('cookies',null)|length %}

{% for cookie in cookiesSettingsGet('cookies') %}

    {% for script in cookie.scripts %}

        {% if script.scripts_disable == 0 %}

            {#  If pages list is set, compare to current page URL #}

            {% if script.scripts_run_pages == true and script.scripts_run_pages_list|length %}

                {% set scriptRunThisPage = false %}

                {% for item in script.scripts_run_pages_list %}

                    {% if url(item.page_url) == url().current %}

                        {% set scriptRunThisPage = true %}

                    {% endif %}

                {% endfor %}

            {% else %}
                {% set scriptRunThisPage = true %}
            {% endif %}

            {# TODO: get rid of those IFs #}

            {% if scriptRunThisPage %}

                {# Test for production mode required first #}
                {% if script.scripts_run_production == false 
                    or ( script.scripts_run_production == true and this.environment == 'production') %}

                    {% if cookie.required or sgCookies[cookie.slug] %}

                        {% if script.scripts_code and scriptRunThisPage %}

                            {% put scripts %}

                                {{ script.scripts_code|raw }}

                            {% endput %}

                        {% endif %}

                        {% if script.scripts_file and scriptRunThisPage %}

                            {% put scripts %}

                                <script src="{{ script.scripts_file|media }}"></script>

                            {% endput %}

                        {% endif %}

                    {% endif %}

                {% endif %}

            {% endif %}

        {% endif %}

    {% endfor %}

{% endfor %}

{% endif %} `

MateThemes commented 2 years ago

Then I don't good the error and the filtering should work fine!

jan-vince commented 2 years ago

I will test it and update - but I would like to get rid of all those ifs :)

MateThemes commented 2 years ago

That would be the best to get rid of the ifs :)

evwerkz commented 2 years ago

I do a pull request. Do not more use "if" on "for " condition.

See this: https://github.com/twigphp/Twig/blob/40b6f59430cc17999406a5557c9e178704e92fa8/CHANGELOG#L135