OleVik / grav-plugin-imgsrcset

Grav ImgSrcset Plugin
MIT License
12 stars 1 forks source link

twig compiler crashes after activating plugin #2

Closed gigago closed 8 years ago

gigago commented 8 years ago

twig compiler crashes after activating plugin deactivating the plugin restores page functionality

…/­vendor/­twig/­twig/­lib/­Twig/­Environment.php669

Whoops \ Exception \ ErrorException (E_ERROR) Cannot use object of type PHPHtmlParser\Dom as array

OleVik commented 8 years ago

What is your twig_first variable set to in system.yaml? A previous issue was solved by setting it to true:

pages:
  twig_first: true
gigago commented 8 years ago

Well, that appears to work. Not too sure about possible side effects though. I would suggest this kind of prerequisite belongs in the installation docs.

Anyway, as long as there's no way to exclude specific folders/files, it's probably not an optimal fit for my purposes. Such a feature would greatly increase the plugin's usefullness.

OleVik commented 8 years ago

The side effects should be negligible, you are in effect just asking Grav to process template-files before content.

What folders or files would you want to exclude? The effect only applies to img-elements in Markdown from pages. I would agree that the process is rather specific, and really the plugins existence stems from Grav not handling dynamically resizing and caching many large images well.

gigago commented 8 years ago

I see, thanks. Of course, it's good to have this functionality at all. In my specific case the site's base images are too small to go to the trouble of serving them at multiple sizes. However, I also use a lightbox without thumbnails for serving up series of high quality images in combination with meaningful comments. So mobile users should preferably be somewhat protected against the huge downloads. I almost got featherlight to do what I need, there's only a nasty problem with redrawing the alternative sources...

OleVik commented 8 years ago

For functionality like a modal with high-res images, but not necessarily responsive images generally, I'd just ensure that images are wrapped and images links rewritten to target bigger images. Since any modal depends on JavaScript, you could just use jQuery to wrap the img-elements and replace the sources so you get the higher resolution ones.

gigago commented 8 years ago

That's an excellent suggestion, a bit like Adaptive Images plugin. However, I do believe I have the featherlight / srcset route working now by kludging the browsers window size when my images have height 0. This turns out to be a particularly powerful method of forcing a redraw, no prisoners! =) It took only 1 1/2 day to find out. (and yes, i have tried all the standard ways of trying to induce the browser to behave nicely) Apparently, chrome has by far the most mature implementation of this functionality now

OleVik commented 8 years ago

Glad you got it sorted. I also added a note in this plugins README about twig_first.