Step 4: Add a Custom Class to Each Taxonomy Term: Name Field
The answer is in Tokens, which Views calls
Replacement Patterns. Tokens are little bits of text,
usually surrounded by brackets (e.g., [link]), which you can use to replace other
text. So, for example, I can create a custom class for each instance of
the Taxonomy Term Name field, by inserting a token
for the name into the CSS class for that field.
Creating the token was a little bit tricky. The first step is find the actual token; to do this, I had to pretend I was rewriting the field.
If you click on the name of any field in your Views settings, you’ll see a few drop-down areas that let you set up different parameters for the field. With the Image field, you already saw the Style Settings variable. If you check out the options under Rewrite Results (see Figure 13-11), you’ll notice an option: “Rewrite the output of this field.” This is highly useful if you want to create very specific code from Views. The rewrite options are how we’ll create our custom class.

Figure 13-11. If we choose the option to rewrite the field’s output, there’s a host of things we can do with it
In order to find the token I needed to create my new Views class, I had to check the option to rewrite the field output. Underneath the checkbox, you’ll see a new dropdown called “Replacement Patterns” (see Figure 13-12). That will give you a list of the replacement ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access