ProcessWire Weekly #129

The 129th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!

Welcome to the 129th issue of ProcessWire Weekly! This time we've got some fresh core development news, a collection of ProcessWire online resources, a handy recipe for speeding up certain search queries, and also a really neat site of the week.

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.39

In his weekly post at the processwire.com blog Ryan introduces the latest dev version of ProcessWire, 3.0.39. This version contains a couple of really useful updates, particularly for anyone regularly working with template files:

  • The functions API provides an alternative, IDE friendly way of accessing the API: instead of $page you can use page(), and so on. These functions will always work regardless of scope, i.e. you can use them as-is even in functions.
  • When using the functions API you also have access to various shortcuts, such as `pages("template=basic-page")` or `page("title")`. The FunctionsAPI.php file contains details about all the accepted params.
  • Another new feature are regions. You can define a region with region('name', 'value') and then output it elsewhere with region('name'). There's a bit more than that to this feature actually, but we'll leave explaining the details to Ryan.

If you are wondering about the region feature and how exactly it differs from just using variables, the main point of having this as a separate feature is that it can make things more obvious and code more readable. It's also IDE friendly, as there are no seemingly undefined variables when you're working with multiple separate files.

Please note that the new functions API is disabled by default, and has to be enabled via $config->useFunctionsAPI = true. With the functions API disabled you can still access these new functions, but you need to use the wire-prefixed versions normally intended for internal use only: wirePage(), wirePages(), wireRegion(), etc.

There's also an updated version of our Skyscrapers demo site out now. This site was rebuilt from scratch using recently added features and the Uikit frontend framework. You can check out the demo site at demo.processwire.com and take a look at the templates at the skyscrapers2 GitHub repository.

For more details about the core updates mentioned here and a recipe for recreating admin thumbnail images when updating to ProcessWire 3.0, don't forget to check out Ryan's latest blog post at the processwire.com blog. Thanks!

Weekly forum highlights, tutorials, and other online resources

Here we've got a new collection of support forum highlights and other useful and/or interesting resources. As always please let us know if there's anything important we've missed so that we can include it in one of our future issues.

  • First of all, a pretty decent LinkedIn Pulse post about ProcessWire and why it makes sense for business owners and developers alike.
  • Our second link is a bit more developer-oriented: an article by António Andrade about deploying ProcessWire with Robo, a PHP task runner.
  • A new module we haven't yet had the chance to introduce properly, RockSVN, adds version control for fields and templates. Please note, though, that this is an alpha release, so extra caution is recommended.
  • Our jobs forum has been active lately, with new jobs popping up pretty much on a weekly basis. The latest one is about forming an ongoing contract partnership.
  • Finally, a development we thought you folks might find pretty interesting: making use of the 6G Firewall (or blacklist, really) in the context of ProcessWire.

If you're interested in ProcessWire news, discussions, and updates, there's always something going on at the support forum. Since we're only able to include a tiny selection of all that in our weekly updates, head down to the forum for more.

Recipe of the week: set up a really simple search index using FieldtypeCache

This week's recipe is actually a ProcessWire Weekly original – kind of. While there's nothing exactly unique about it and it has been used and even mentioned at the support forum before, but we thought it'd be worth sharing nevertheless.

The problem

You have a search page – be it your regular site search or something more specific, such as a search feature for contacts list. While you need to perform a text search to multiple fields, you also want to keep things fast.

Searching from multiple fields is easy, but if overused, it can really kill the performance of those search queries. We need a solution that finds content from multiple fields with just one query. In other words: we need a search index.

The solution

We're going to use the native Fieldtype Cache to build a rudimentary search index:

  1. First of all, go to Modules and install a Core module called FieldtypeCache.
  2. Add a new field "search_cache" and select "Cache" as it's type. Save the field.
  3. On the Details tab choose the fields you want to make searchable. Save again.
  4. Add "search_cache" to all templates you want to include in your search results.
  5. Optional but recommended: use the "Regenerate Cache" option found from the Details tab of the field to make existing content instantly searchable.

With the cache field now in place, all you need to do is use it in your search page, just like you would use any other field:

<?php
$q = $sanitizer->selectorValue($input->get->q);
if ($q) {
    $pages->find('search_cache%=' . $q);
    // ... do something with the results ...
}

Please note that if your PHP version is lower than 5.4, FieldtypeCache escapes multibyte Unicode characters as \uXXXX. We can't really recommend using PHP < 5.4, but if you do, this is worth keeping in mind. Apart from that, this is a pretty neat way to notably speed up certain types of queries.

If you've got a recipe of your own that you'd like to share with others, feel free to submit it at ProcessWire Recipes.

Site of the week: Fabricius

Fabricius is a brand new site produced to introduce a new building currently being built at Hamburg, Germany. This beautiful site was designed and developed by Jan Ploch, Hamburg-based graphic designer.

While technically this is a single page web site, there's quite a lot of content on that page: regular text and images, a Google map with custom style and icons, an imagemap for per-apartment details, custom contact form, and a whole bunch of downloadable, automatically generated PDF documents.

Behind the scenes this site is powered by ProcessWire 3.0. Some of the modules used on the site include Map Marker for the Google map, Pages2PDF for autogenerated PDF files, MarkupSrcSet for responsive images, and AIOM+ for merging and minifying HTML, JavaScript, and CSS resources.

You can find more details about this project, including the print materials designed in tandem with the site, from Jan's portfolio. If you have questions for the author himself, the Fabricius showcase forum thread is a good place to start.

Big thanks to Jan Ploch for sharing this project with us – downright stunning work!

Stay tuned for our next issue

That's it for the 129th issue of ProcessWire Weekly. We'll be back with more news, updates, and content Saturday, 5th of November. 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!

This post has 3 comments:

Ryan on Saturday 29th of October 2016 18:41 pm

Great issue Teppo. Just a quick thing to mention about the recipe: you'd want to use the selectorValue() sanitizer rather than the text() sanitizer.

Teppo on Monday 31st of October 2016 17:19 pm

Thanks, Ryan. Good point, updated the recipe :)

Jansie on Thursday 3rd of November 2016 22:36 pm

Great article. Thanks Teppo.

I'm finally moving to Processwire, after years of threatening. It's slow going, but I've started. I find that things make sense if you spend a lot of time with the system.

Might create a range of uber-noob friendly Processwire articles, just to get people like me onto the system.

Post a comment