Frequent Twig Runtime Errors

I have my development server working. I use Chrome with MAMP Pro and have CodeKit doing the auto-reload duties. All is generally well.

If I do something as simple as change the text in a .md file and then save, CodeKit see the changes and refreshes the page. Perfect.

But every time it does, I get a Twig error:

An exception has been thrown during the rendering of a template ("Undefined offset: 0") in "partials/navigation.html.twig" at line 25.

If I manually reload that page, it’s fine again.

But why the frequent errors?

I think you can work with CodeKit with disable the cache system from Grav. When you reload the page Grav check if need to refresh internal cache or not, with CodeKit Grav not refresh anything, then Twig get error. This is my idea, you can try to confirm :slight_smile:

@namaless is right, it’s again related to caching, but I think its because CodeKit is caching things it doesn’t really know about. Maybe you can disable that cache in CodeKit?

Another alternative that I know i’ve mentioned to you before, is just to use SCSS without codekit, and that combined with a simple CSSRefresh bookmarklet will get you the same result without any fuss. Plus you don’t need to set things up and configure them as you do with CodeKit.

I gave Grunt a run this morning (I used to use it) for setting up an express.js server, live reload, scss and autoprefix. But I ended up getting wrapped around the axle of configuration and tasks, so left it for another day.

Really in Antimatter there is only scss to compile, and that is a one liner:

scss --watch scss:css-compiled

That’s it, it will watch the scss directory and compile the resulting files into the css-compiled folder. That’s it.

I don’t bother with any auto refresh myself, but that one i linked to above can detect css file changes and reload the page.

I guess I carry the Grav mentality with me. I don’t like overkill, I like using the best tool for the job, and given the choice of multiple tools that do the same job, I like to picker the simplest.

Well, maybe there’s a simpler way I can be going after this. I want to:
compile scss to css on saved changes
apply autoprefixer to the resulting css
auto refresh the browser on changes to .md, .twig, .css, .yaml, .php

I sure don’t need to do any of that. But it’s how I roll. :slight_smile:

CodeKit is nice because there is very little configuration to do and it handles all of the above and more. Plus it’s a nice Mac-like interface and well supported. Perfect!

I think Grunt would be fine, too, and allows more fine-grained configuration. But I don’t always think like Grunt, as my exercise this morning showed. I went there again to minimize caching outside of Grav. But Chrome 39 doesn’t seem to like its Live Reload plugin anymore, which lead me to express.js and into a ditch. :frowning:

FYI you don’t need to autoprefix, because SASS does that for you by default. Grunt is good for compiling JS and performing more complex tasks, for just SASS compilation, it’s more trouble than it’s worth.

Of course you can do what you like, but we develop themes and extensions for a living, and this is my professional and highly experienced opinion :slight_smile:

OK. I got Grunt running (I know, I know…) and CodeKit out of the loop. I can now save changes to a .md file and Firefox reloads the page without a Twig runtime error.

CodeKit was up to something, although the developer tells me it caches nothing and explicating bust caches. Maybe it’s busting Grav’s caches?