Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


nbcommunication last won the day on January 13 2021

nbcommunication had the most liked content!

1 Follower

Profile Information

  • Gender
    Not Telling
  • Location
    Lerwick, Shetland

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

nbcommunication's Achievements

Sr. Member

Sr. Member (5/6)




Community Answers

  1. Just implemented this in combination with a $cache-ing of the $pages->find() query. Lightning fast. if(file_exists($file) && filemtime($file) > $page->modified) { Would it not be $item->modified? Cheers, Chris
  2. Today I needed to implement a background image with sources, using the new UIkit Image component implementation: https://getuikit.com/docs/image#picture-sources PageimageSource doesn't do this out of the box, but I found I neat solution, which I thought I'd share: <?php // $bannerImage = Pageimage; preg_match_all('<source\ssrcset="(.*?)"\ssizes="(.*?)"\stype="(.*?)">', $bannerImage->render(), $matches); $sources = []; foreach($matches as $index => $match) { if(!$index) continue; $sources[$index] = []; foreach($match as $i => $v) { $sources[$index][[ 'srcset', 'sizes', 'type', ][$i]] = $v; } } echo '<div class="uk-background-cover" sources="' . $sanitizer->entities(json_encode(array_values($sources))) . '" data-src="' . $bannerImage->url . '" data-uk-img></div>'; This assumes that the render() function is returning a <picture> element. Cheers, Chris
  3. Hi @neophron, Apologies for the late response. This is a bit of a cop-out answer, but there are no prescriptions for srcset/sizes. What is right is whatever works best for your use case. The only way to get there is to experiment. That said, perhaps this is what you should do? <?php echo "<img class='photo' src='{$slide->size(760, 0, $options)->url}' srcset='{$slide->url} 2x' alt='{$slide->description}' loading='lazy'>"; Regarding the 'orientation: portrait' sizes attribute - this isn't to do with the image's orientation, it is the device orientation. You can use it to specify a size profile for this e.g. <?php // Render an image using custom set rules and sizes // These rules will render 'portrait' versions of the image for tablet and mobile // Note the advanced use of the `srcset` option passing both `rules` and image `options` // WebP is disabled // Picture is disabled echo $image->render([ 'srcset' => [ 'rules' => '320x569, 640x1138, 768x1365, 1024, 1366, 1600, 1920', 'options' => [ 'upscaling' => true, 'hidpi' => true, ], ], 'sizes' => '(orientation: portrait) and (max-width: 640px) 50vw', 'picture' => false, ]); // <img src='image.jpg' alt='' srcset='image.320x569-srcset-hidpi.jpg 320w, image.640x1138-srcset-hidpi.jpg 640w, image.768x1365-srcset-hidpi.jpg 768w, image.1024x0-srcset-hidpi.jpg 1024w, image.1366x0-srcset-hidpi.jpg 1366w, image.1600x0-srcset-hidpi.jpg 1600w, image.jpg 1920w' sizes='(orientation: portrait) and (max-width: 768px) 50vw' loading="lazy"> I'm not 100% myself on how the above actually works, but it provides '2x' portrait images for small portrait devices e.g. mobile. If there's one bit of advice I'd give with srcset, it is keep it simple! I hope that helps. Cheers, Chris
  4. Hi @Stefanowitsch, Sorry for the late reply. I've had a quick look this morning and for me the variations are being regenerated correctly after a change of focus, but the browser's image cache is the issue - the filename doesn't change after the focus change so it just displays the old one it has cached. Hopefully the brief screencast attached will demonstrate. I'm not sure I can remedy this - will have a look when I can to see what's been suggested elsewhere for the issue. Cheers, Chris Screen Recording 2021-11-29 at 08.35.37.mov
  5. Hi @Stefanowitsch, I'm always using UIkit when developing so either make use of the Image component which has background image srcset functionality, or if using the <picture> element functionality of this module, I use the Cover component. Cheers, Chris
  6. Hi, Is anyone else finding that noSlashUrls is no longer respected on top-level (e.g. /page-name) pages on 3.0.186? Cheers, Chris
  7. Hi @sodesign, Haven't found a workaround, but can confirm @Clarity's message above is correct. For us it happens on sites which are querying external APIs every so often and updating the site data based on the results. Cheers, Chris
  8. Hi @Stefanowitsch, Thanks. I'll leave the implementation as it is at the moment, if there are further reports of the issue I'll investigate further. Cheers, Chris
  9. Hi @elabx, Apologies it has taken a while to get back to you. From what I've been able to determine, the browser selects the first <source> in the list in the absence of media queries. In this case the webP version would always be selected as it comes first. I've added a couple of things that can help with the issue. The first is the ability to disable the render() extensions, falling back to the default Pageimage:render() method. This is done by passing $options as false. Here's an example, where if the webP image url isn't actually webP due to it being larger it uses the default render(). <?php echo $pageimages->each(function($pageimage) { return strpos($pageimage->webp()->url, '.webp') === false ? // If the webP url is not webp $pageimage->render(false) : // Disables the PageimageSource::render() extensions $pageimage->render(); }) The second is a similar option to the $config->webpOptions option 'useSrcUrlOnSize'. If this is enabled, the module checks to see if the webP url is actually webP (as in the example above) and if it is not (e.g. if it is a .jpg), then it disables webP for that image, which in turn disables the picture option: <?php echo $pageimage->render([ 'useSrcUrlOnSize' => true, ]); This takes the module to v 1.0.2, still in beta. Cheers, Chris
  10. Hi @Stefanowitsch, It is working for me with that example. Do you have access to any other server environments to test it out? I'm wondering if it may be related to this issue described here: https://stackoverflow.com/questions/7456939/what-is-the-preg-match-all-u-flag-dependent-on Cheers, Chris
  11. Hi @Stefanowitsch, It is definitely working for me. It suggests that perhaps unicode support isn't available on your server? Could you supply an example caption that isn't working? I've been testing with a caption that uses the characters you mentioned but I'm maybe missing something. Cheers, Chris
  12. Hi @Stefanowitsch, preg_match_all on line 1045 required a unicode flag. I've added that and released 1.4.3. That should hopefully be working for you now - please let me know if not! Cheers, Chris
  • Create New...