The latter type of layer state is called a query. Queries can identify layers that match any combination of layer tag, type, name and lock status.
You could use a query to instantly hide all layers tagged red to ensure they’re excluded from output. Or, you might use a query to toggle the visibility of all adjustments and live filters for an instant before-and-after comparison.
Queries can select objects too. If you create document templates, you might use a query to select all image layers you’ve tagged grey to indicate they should be removed before distribution, for example, and then delete them all with a key press.
These are just a few example applications. There are other ways you can use queries to improve your workflow.
Here, we’ll explore how you can use them to build and output multiple deliverables from a single Affinity document, helping to smooth the process of working through clients’ revisions.
Creating queries
Queries are created and managed on the States Panel, which is available via the Window menu.
At any time, you can show, hide or select all layers that match a query’s criteria with a single click.
The States panel is also where you manage captured states. A captured state affects only layers that existed when it was created. A query affects all layers, including those added after the query was created.
Our example document
We’ll demonstrate queries using this 23-page golf course brochure in Affinity Publisher, but note that the feature is available in Affinity Designer and Affinity Photo too.
Our client has approved the design and commissioned the following deliverables:
- English versions for each of its three golf courses, with some text and images being course-specific.
- Translations in French, German, Spanish and Japanese.
Ordinarily, you might create a separate Affinity document for each deliverable. However, even if good practice is followed—using Affinity features such as text styles and global colours—certain types of change would have to be repeated in all the documents.
Alternatively, we can create all brochure variations in one Affinity document, follow a consistent layer naming convention, and use queries to quickly switch to any variation of the document. Revisions to common design elements then only have to be performed once.
Here’s the layer stack for the first pair of facing pages in our initial document.
On this spread, the layers that will differ between deliverables are:
- The course description
- The largest photo
- The driving range and restaurant photos at the lower right.
Everything else on the spread is the same for all deliverables.
Here’s how the layer stack looks after adding content for all three courses. For each course-specific design element, we have:
- Duplicated its layer, so there’s a copy for each golf course.
- Replaced each new layer’s content with course-specific text or imagery.
- Named each of these layers after its related course.
- Grouped layers by design element so the document is easy to navigate.
Switching between variations
Next, we’ve created one query for each golf course. As long as Scope at the bottom of the States Panel is set appropriately, we can switch between course variations of the document in just three clicks!
The queries are almost identical. They all ignore layer tags, types and lock status. For our purpose, we only need to inspect layer names, so each query’s layer name criterion contains a different course name.
Regular expressions
You may be wondering why we’ve typed additional characters–(?i)—in front of the course names in the queries.
They relate to the Regular expressions setting, which we’ve enabled. When the setting is disabled, Affinity considers a layer’s name to be a match if it is literally what you’ve typed in the box.
Regular expressions allow Affinity to match layer names to a pattern, i.e. a specification.
The additional characters we’ve included tell Affinity to ignore the case of letters. So, it won’t matter if we’ve mistyped a layer name all in lower case—for example, description shetland—or starting with two upper-case letters—MAplewood), say.
Care is still needed to avoid outright misspellings, though.
Trying it out
Having set up all three queries, we can click Hide—the struckthrough eye—on two of them and Show—the open eye—on the other to view a different course’s layers.
With the groundwork laid, the earlier work of adding and organising layers for each golf course needs to be repeated for the document’s other pages.
While doing so, we ran into a problem on the brochure’s back page. It contains a location line with all three golf course names, which has been automatically named using the start of the text.
Currently, our queries can cause this layer to be unintentionally hidden.
One way to deal with this is to manually name the problematic layer, e.g. Location Line. That would work but isn’t a scalable solution for documents that contain many auto-named text layers. It’s better to make a small change to the naming of layers we want to affect.
So, course names are now preceded by a hyphen, and we’ve updated our queries accordingly. This character sequence is unlikely to occur in auto-generated layer names.
Consider possibilities like this when devising your own naming convention.
Let’s go multilingual
We can continue with this approach to handle the client’s request for brochures in additional languages.
Much like we did for each golf course, we’ve created duplicates of this spread’s text and image layers.
For each language, we’ve appended a hyphen and a short country code to each layer group’s name, e.g. -FR for French layers and -JA for Japanese.
Here’s the query we’ve created to toggle French text layers.
The dollar sign at the end of our regular expression tells Affinity to match layer names that end with the specified pattern. Layer names that coincidentally contain the same characters—in an earlier hyphenated word, for example—will be ignored.
We’ve repeated this for all pages and created a query for each language. Toggling between document variations requires a few more clicks than before in order to show content for only one golf course and one language.
Even so, the organisational work we’ve done will make revision rounds from the client easier to handle.
Learn more about layer states
Bear in mind that we’ve shown just one scenario for using layer states. The feature can help out in many other ways. These tutorials cover some further use cases in Affinity Publisher, Photo and Designer.
It’s also worth noting that we’re working on further improvements to layer states to make the feature even better.