1

Working on fixing a lot of deprecated code, enviroment is setup as dev so getting a lot of warnings. Some are easily idetified, others are pretty generic and come from core files. Doesn't show where the issue is... So I have been going through each block template removing code till the page loads to narrow it down.

Example Warning: strtolower() expects parameter 1 to be string, array given from /vendor/craftcms/cms/src/helpers/Db.php

 $firstVal = strtolower(reset($value));

I have narrowed an existing issue down to the following code from a block template, however I have tried a few different ways but the page will not load with the following code. Anyone know a way to resolve this, it seems to be an issue with the relatedTo

Source of problem? Setting up section

{% for feed in block.feeds %}
    {% if feed == 'all' %}
        {% set data = ['blog', 'caseStudies', 'dataSheets', 'events', 'news', 'webinars', 'whitePapers', 'artices', 'productDemos'] %}
        {% set break = true %}
    {% else %}
        {% set data = data|merge({ (loop.index0):feed }) %}
    {% endif %}
{% endfor %}

Source of problem? Setting up relatedTo

{% for related in block.relatedTo %}
    {% if related == 'All' %}
        {% set reldata = false %}
        {% set break = true %}
    {% else %}
        {% set reldata = reldata|merge({ (loop.index0):related }) %}
    {% endif %}
{% endfor %}

Then Setting up the query seems to be an issue with the section(data) but not sure what needs changed as I do not see a clear deprecation warning, or stacktrace

{% if reldata %}
    {% set tag = craft.tags.title(reldata) %}
    {% set feat = craft.entries.section(data).relatedTo(tag).limit(8).all() %}
{% else %}
    {% set feat = craft.entries.section(data).limit(8).all() %}
{% endif %}
1

This seems to have fixed the issue.

{% if reldata %}
    {% set tag = craft.tags.title(reldata|join(', ')) %}
    {% set feat = craft.entries.section(data|join(', ')).relatedTo(tag).limit(8).all() %}
{% else %}
    {% set feat = craft.entries.section(data|join(', ')).limit(8).all() %}
{% endif %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.