I'm trying to set up caching and have it disabled for my local environment using {% cache unless craft.config.devMode %}. This works fine on non-local environments, but on my local environment I'm getting the error Method "devMode" for object "Craft\ConfigVariable" does not exist. Even though it does, this is my config file:

return array(
    '*' => array(
        'addTrailingSlashesToUrls' => true,
        'omitScriptNameInUrls' => true,
        'enableCsrfProtection' => true,
        'cpTrigger' => 'example-admin',
        'siteUrl' => (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://" . $_SERVER['HTTP_HOST'],
        'environmentVariables' => array(
            'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/data/uploads/',
            'baseURL' => (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://" . $_SERVER['HTTP_HOST'] . '/data/uploads/',
    '.local' => array(
        'devMode' => true

If I {{ dump(craft.config.devMode) }} I get bool(true) so it is being set, it's just when being used in the cache conditional.

  • Strange. What does this do: {% if craft.config.devMode %}Check DevMode{% endif %}? – carlcs Nov 13 '14 at 11:58
  • That worked, must be character encoding as when I manually typed out {% cache unless craft.config.devMode %} it worked. – KeironLowe Nov 13 '14 at 12:00
  • No solution to this, but what about setting a new variable 'cache' => true? Then you can set it independently from dev mode. – carlcs Nov 13 '14 at 12:02

Looks like it was an issue with character encoding. I copied the {% cache unless craft.config.devMode %} from What are the best practices for using the {% cache %} tag?.

When I manually retyped out the conditional it worked properly.

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.