ProcessWire Weekly #249

In the 249th issue of ProcessWire Weekly we're going to walk you through the latest core updates (ProcessWire 3.0.126), introduce a new third party module called Page Access Releasetime, and pick a new site of the week. Read on!

Welcome to the latest issue of ProcessWire Weekly. This week we've got some new core updates to share, and particularly one new $page API method that we believe will make your life a tad easier. In other news we're going to take a closer look at a recent release – a third party module called Page Access Releasetime.

Our latest site of the week belongs to the south-west Germany based photographer Anna Wawra, and as always we're absolutely thrilled to cover a site belonging such a talented artist. Anyhow, more about that in just a bit – first we've got some core and module news to share.

One more update before we jump to the main content, though. We'd like to thank again netcarver for doing an amazing job in getting the processwire-issues repository back in shape. The issue number has been going steadily down, many smaller issues have been resolved, and right now things are looking really good in that regard.

So... thanks, Steve! Really appreciate what you're doing there :)

Thanks to all of our readers for being here with us again, and as always, any feedback is most welcome – please don't hesitate to drop us a line if there's anything in your mind you'd like to share with us. Enjoy our latest issue and have a great weekend!

Latest core updates: ProcessWire 3.0.126

In his latest post at the processwire.com blog Ryan covers ProcessWire version 3.0.126, which is now available via the dev branch at GitHub. This version includes various bugfixes, as we've been working through the open issues in the processwire-issues repository, but there's also one new addition to the API: $page->if() method.

While we won't go into more detail here, in case you're interested you can check out the full GitHub changelog for the past week for a detailed list of changes between versions 3.0.125 and 3.0.126. That being said, most of those changes are minor bugfixes or other tweaks – such as moving a method to more sensible location.

Introducing the $page->if() method

This newly added core API method takes three parameters, although technically only the first one is required: $page->if($key, $yes, $no). The idea is to return the $yes value if the value provided for $key is considered "truthy", otherwise return the value provided for $no:

  • If $key is a field name, we check if that field has a value.
  • If $key contains a selector string, we check if $page matches it.
  • If $key is an integer or a boolean, we return $yes or $no based on it.

In other words this feature is mainly a handy shortcut that allows you to check a conditional clause or field value and define success and failure results in one go – but there's also a bit more intelligence here than you would get with just a regular PHP "if". For an instance empty WireArrays and NullPages, which would otherwise require some extra logic to check, result in the $no value being returned.

// if summary is populated, output it in an paragraph
echo $page->if('summary', '<p class="summary">{summary}</p>');
// if price is populated, format for output, otherwise ask to call for a price
echo $page->if('price', function($value) {
    return number_format($value) . '€';
}, 'Call us');

The benefits of this feature become quite apparent in the case of HTML-producing template files. For an example this ...

<h1><?= $page->title ?></h1>
<?php if ($page->summary): ?>
    <p class="summary"><?= $page->summary ?></p>
<?php endif; ?>

... can now be shortened to this:

<h1><?= $page->title ?></h1>
<?= $page->if('summary', '<p class="summary">{summary}</p>') ?>

As you can see from the examples above, both $yes and $no support multiple types of values: they can be strings with or without {placeholders}, field names, callable functions – or you can leave $no empty to return an empty string, or both $yes and $no empty to return a boolean.

For more details about how $page->if() works, and where you might find it most useful, be sure to check out the blog post from Ryan. Thanks!

New module: Page Access Releasetime

Page Access Releasetime is a new third party module developed by Sebastian Schendel. In a nutshell this module lets you define when a page becomes viewable, and when it should become non-viewable again.

In many ways this is similar to the SchedulePages module, except that instead of publishing or unpublishing pages, Page Access Releasetime does it's magic without managing the publish state of a page, by hooking into methods such as Page::viewable() instead. In some ways this is definitely a simpler approach, and it doesn't trigger any unrelated hooks attached to state changes – although which method is preferable definitely depends on the use case at hand.

Assuming that you've enabled the $config->pageFileSecure setting, this module also protects files of non-viewable pages by additionally hooking to Page::isPublic() and ProcessPageView::sendFile(). One thing to note is that in the current implementation pages made non-viewable using this module still appear in $pages->find() queries, and need to be specifically excluded by an additional check to $page->viewable().

If you want to give this module a try, you can download or clone it directly from the Page Access Releasetime GitHub repository. If you have any questions or want to know more about how this module works, check out the Page Access Releasetime support forum thread. Thanks to Sebastian for sharing this module with us – it's definitely a useful addition, and we're happy to have it around. Keep up the great work!

Site of the week Anna Wawra Fotografie

Our latest site of the week belongs to a photographer based in the south-west Germany, Anna Wawra. This responsive website, designed and implemented by miratheresia design studio, has a clear design to call full attention on the photographs, and there's also a password protected area for customers to view their own private content.

The design of this site, as mentioned above, is really clean and simple, with photographs – which, for the record, are downright stunning in themselves – being the primary content. Only non-image-oriented pages are the contact page that holds a contact form and some other details, and the impressum page. The private customer area requires authentication, and according to the portfolio page at miratheresia studio's site contains material shared with the customer.

Not much we can say about the behind-the-scenes implementation here: the site itself is quite simple, and as such makes use of no full-blown front-end framework, at least one that we might've recognized. Images are displayed using carousels, and this is a somewhat curious combination of Slick, Flickity, and PhotoSwipe – apparently the large carousel on the home page is powered by Slick, other carousels by Flickity, and lightbox feature is provided by PhotoSwipe.

Thanks to the team at miratheresia design studio for sharing this project with us, and congratulations to Anna Wawra for her amazing website. Brilliant work from all parties involved!

Stay tuned for our next issue

That's it for the 249th issue of ProcessWire Weekly. We'll be back with more news, updates, and content Saturday, 23rd of February. As always, ProcessWire newsletter subscribers will get our updates a few days later.

Thanks for staying with us, once again. Hope you've had a great and productive week, and don't forget to check out the ProcessWire forums for more interesting topics. Until next week, happy hacking with ProcessWire!

Post a comment