ProcessWire Weekly #248

In the 248th issue of ProcessWire Weekly we'll introduce a third party module called SEO Maestro, feature a handy little recipe of the week, and showcase a brilliant new site of the week called Urban Alternatives. Read on!

While there are no major core updates this week (just a couple of minor additions to the Sanitizer), we've got other updates for you folks: a new third party SEO and meta data management module called SEO Maestro, a brand new recipe of the week – it's been a while since we last featured those! – and an amazing new site of the week.

In case you haven't been keeping track of the latest developments at GitHub, this week we have been working towards resolving any open issue reports, or updating them with the latest details. Largely thanks to the efforts of netcarver and Ryan we've managed to squash a number of bugs in the dev branch – so if you've been using the dev branch, you might want to consider giving the latest version a try.

Obviously the issue count itself isn't such an.. err, issue, but having outstanding issues is, so big thanks to everyone involved in this cleanup operation. That being said, if you happen to find a problem with ProcessWire, please don't hesitate to open a new issue at the applicable GitHub repository – that way we can deal with it as soon as possible. The squeaky wheel gets the grease, as they say.

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!

New module: SEO Maestro

This week we're thrilled to introduce the latest addition to our modules directory – a SEO and meta data management module by Stefan "Wanze" Wanzenried: SEO Maestro.

As the author so modestly puts it, SEO Maestro is a module helping you to manage SEO related tasks like a boss, and the list of features provided out of the box is indeed quite formidable. Seo Maestro ...

  • Automatically generates and maintains XML sitemap for your pages.
  • Includes both a Fieldtype and an Inputfield to manage sitemap settings and meta data for pages (title, description, OpenGraph, Twitter, etc.)
  • Provides built-in multi-language support, applicable to both the sitemap and all your meta data fields.
  • Provides configurable meta data default values on template level, while providing the ability for pages to inherit or overwrite those defaults.
  • Maps existing page fields to meta data values, thus greatly reducing the need to manually duplicate content.
  • Automatically handles common meta tags, such as canonical, alternate, and generator (added in the latest release, SEO Maestro 0.4.0.)

After setting the module up, you get a SEO field in the Page Editor, which contains all the necessary settings for that specific page. You can configure included options and their default values via the module configuration screen, and easily render filled in values on the front-end of your site using via API:

// Render all meta tags, including the common ones:
echo $page->seo->render();
// Render only the opengraph tags:
echo $page->seo->opengraph->render();

For a detailed introduction to the module and proper usage examples, check out the SEO Maestro GitHub repository. If you have questions or suggestions for the module, feel free to post them via GitHub, or through the SEO Maestro support forum thread.

This module can be installed manually by cloning or downloading from GitHub, or you can use the built-in module installer to get it up and running in no time. Big thanks to Wanze for sharing this module with us – amazing job, as always!

ProcessWire recipe of the week: exact match queries using Page reference fields

It's been a while since we last posted a recipe of the week, and this one felt so useful that it just had to be shared. The recipe we're sharing here started out as a question from Adrian about exact Page reference matches, which he later turned into a snippet of code that got picked up by Robin and turned into a helper method – before Robin finally arrived at a final, and rather elegant, solution.

The problem

When we want to find a page that contains a value – or multiple, predefined values – in a Page reference field, that's a simple one. If we, say, want to find all travellers that have been to Albania and Andorra, we can handle it like this:

$matches = $pages->find('template=traveller, countries=Egypt, countries=Fiji');

Now, what if we only wanted to see results with that specific match, or those specific matches in case of multiple values?

That's where things start to get tricky, since there's no such thing as an "exact match query" in our arsenal. We can, of course, match multiple values, or filter out the values that we don't want to match – but this often requires a loop to construct the selector value, and overall fells like a crude solution to a (seemingly) simple problem.

The solution

Skipping the early iterations, here's the simple, quite elegant solution that Robin ended up with:

$matches = $pages->find(
    'template=traveller, countries=Egypt, countries=Fiji, countries.count=2'

The trick, as you can see, is using count to make sure that the matches include selected values, and the selected values only. Just like that, we've got the set of exact matches that we were looking for.

Now, to take this one step further, here's what you could do if your needs were more complicated than that:

$countries = $pages->find('template=country, title=Egypt|Fiji|Finland|...');
$matches = $pages->find(
    $countries->each('countries={id}, ')
    . "template=traveller, "
    . "limit={$countries->count}"

In this case we're first storing all expected values in a PageArray called $countries, then generating a comma-separated list of countries using the PageArray::each() method, and finally calculating our limit value based on the amount of items in said PageArray. This way there's little manual work, and adding more possible values later is a breeze.

Again, thanks to Adrian and Robin for this one – that's one clever trick right there!

Site of the week: Urban Alternatives

Our latest site of the week belongs to Urban Alternatives – a collaboration of different actors which are united in their efforts to create a more democratic, just and sustainable world.

It's always great when we get to pick a site of the week that not only looks and performs great, but also has a great story behind it. In the case of Urban Alternatives we can tick all those boxes: this map heavy site seeks to highlight initiatives that work towards a better future for us all. Proposals for new initiatives not yet listed can be made by anyone directly on the website.

Technically this site is one big map, with initiatives grouped by cities, and a pull-out menu on the left side. There are info pages, but you're always viewing them along with the map – hence "map heavy". The map itself is powered by Mapbox, and data is acquired from OpenStreetMap. While you navigate the site, content is fetched using AJAX requests, while URLs are automatically kept in sync using the History API.

It's probably worth mentioning that while the site makes rather heavy use of JavaScript, it actually also works very well without it – a nice and progressive implementation, that is. There isn't, as far as we can tell, an actual front-end framework in play here, but the styles are organized using BEM architecture (or something very similar to that).

This site is a joy to use and performs exceptionally well as well, so thanks to the team at Neue Rituale for sharing it with us. Also our congratulations to the client, European Alternatives, and any other collaborators in this project, for their new website!

If you'd like to read more about this project, head down to the Neue Rituale case story for Urban Alternatives, which provides more insight into the project and the process behind the end product.

Stay tuned for our next issue

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