nystudio107 / craft-webperf

Webperf helps you build & maintain high quality websites through Real User Measurement of your website's performance
https://nystudio107.com/plugins/webperf
Other
25 stars 2 forks source link

Unknown parseEnv function on Page Performance Details #11

Closed jmcgaha closed 5 years ago

jmcgaha commented 5 years ago

I have a site still on 3.0.39 and when I'm on an entry and click "Page Performance Details" I get a twig error:

Twig Syntax Error – Twig_Error_Syntax
Unknown "parseEnv" function.
 in /chroot/home/domain/vendor/nystudio107/craft-webperf/src/templates/performance/_includes/backend.twig at line 120

{% set webpageTestApiKey = parseEnv(webpageTestApiKey) %}

I remember seeing parseEnv in recent craft release notes and it looks like maybe it was added in 3.1. I was able to check on our staging server which has 3.1 on it and it worked fine. So maybe required version needs bumped up or something.

khalwat commented 5 years ago

hmmmm. I don't see how that could be? It's wrapped in a conditional:

        {% set webpageTestApiKey = settings.webpageTestApiKey %}
        {% if craft.webperf.craft31 %}
            {% set webpageTestApiKey = parseEnv(webpageTestApiKey) %}
        {% endif %}

craft31 comes from:

        self::$craft31 = version_compare(Craft::$app->getVersion(), '3.1', '>=');

This doesn't make sense...?

jmcgaha commented 5 years ago

Yeah I double checked just to make sure the site didn't get updated without me knowing. Craft 3.0.40.

So then I went and edited the backend.twig file starting on line 119.

{% if craft.webperf.craft31 %}
    Craft 3.1
    {# {% set webpageTestApiKey = parseEnv(webpageTestApiKey) %} #}
{% else %}
    Not Craft 3.1
{% endif %}

The page now loads and outputs the text "Not Craft 3.1". If I unhide the parseEnv line the errors returns. Not sure why its evaluating to false but then still running the parseEnv stuff, but that's what appears to be happening.

khalwat commented 5 years ago

Weird. Alright, I guess I'll have to pick a different way to do this. I'm assuming that Twig probably tries to tokenize the entire template, so if a particular function doesn't exist, it'll error when compiling the template, whether or not the code path is taken or not.

khalwat commented 5 years ago

Fixed in https://github.com/nystudio107/craft-webperf/commit/babf109dfda18925a614c4f3b4711239844fe607