Magento – Apply Unique Styles to each Section of Layered Navigation

Default Layered Navigation
Default Layered Navigation

In Magento, anchor pages that give us layered navigation are, by default, enclosed in dt tags (subheadings) and dd tags (links), respectively. You can control how they look in the default template by changing css/boxes.css .narrow-by styles.

The problem, though, is that I need to change individual sections of the layered navigation. I think I have a decent solution.

Out of the Box

As shipped, the default template displays as shown left. Each of the various filters are presented in exactly the same format. They are all using the same style from css/boxes.css.

In our case, though, we wanted to highlight the “Category” section. I figured we could tweak template/catalog/layer/view.phtml just a little bit such that we could assign a style to each dt and dd, and

Color Highlighted Navigation

name them individually.

To the right you’ll see a pretty obnoxious demonstration of what we were after but it’s a pretty darn good example of what we need to accomplish.

Here’s the default code:

45             <dl id=”narrow-by-list”>
46                 <?php $_filters = $this->getFilters() ?>
47                 <?php foreach ($_filters as $_filter): ?>
48                 <?php if($_filter->getItemsCount()): ?>
49                 <dt><?php echo $this->__($_filter->getName()) ?></dt>
50                 <dd>
51                 <?php echo $_filter->getHtml() ?>
52                 </dd>
53                 <?php endif; ?>
54                 <?php endforeach; ?>
55             </dl>

In the new code, I’m placing the filter’s name – from the  $this->__($filter->getName()) function – into a variable called $__mxw.  Once it’s in $__mxw, I’m going to use it to invent unique style names for each section.
45                 <dl id=”narrow-by-list”>
46                 <?php $_filters = $this->getFilters() ?>
47                 <?php foreach ($_filters as $_filter): ?>
48                         <?php if($_filter->getItemsCount()): ?>
49                         <?php $__mxw=$this->__($_filter->getName());?>
50                         <dt class=”<?php echo “_up_dt”.$__mxw;?>”>
51                             <?php echo $__mxw;?>
52                         </dt>
53                         <dd class=”<?php echo “_up_dd”.$__mxw;?>”>
54                             <?php echo $_filter->getHtml() ?>
55                         </dd>
56                     <?php endif; ?>
57                 <?php endforeach; ?>
58             </dl>

On line 49, I’m grabbing the name into $__mxw. One line 50, I’m creating a unique class name by combining “_up_dt” with the filter name. For Category, I end up with _up_dtCategory, for example. Similarly, I use the $__mxw variable again on line 53 to create a unique class name for the dd tag. For Category, I get _up_ddCategory.

CSS Additions

Now that I’m giving each dt/ dd tag set a unique class, it’s time to define the style.

In css/boxes.css I added styles like these:

785 .narrow-by ._up_dtCategory {
786     color: #000;
787     background-color: #ffff99;
788 }
789
790 .narrow-by ._up_ddCategory {
791     color: #000;
792     background-color: #ffff99;
793 }

Our new view.phtml will produce unique names for each dt/ dd section, so markup all the sections any which way you want.

Request Tracker RT 3.8.1 on Fedora: /etc/aliases: mail aliases for Queues

I am writing this more for future me than anything else. We’d set up our help desk (well, technically our .bash_profiles on our various servers) such that any root access would be logged to RT.

We’d originally set it up to go to our generic help desk queue, but that quickly proved annoying. First of all, we’re in the midst of bringing all sorts of web services online, and this requires a lot of root access. And second, I don’t want root access messages getting lost among the various “Freddy Can’t Print his Email” tickets.

RT makes this oh so easy. With a few caveats that really have nothing to do with RT, it has to do with mail.

The RT Queue

In RT, I created a queue called rootAccessAlerts. I set its Reply and Comment Address to root.access@my.rtserver.com.

/etc/smrsh and rt-mailgate

First, you should familiarize yourself with smrsh, the restricted shell that allows sendmail to execute  commands found only in the /etc/smrsh directory.  This looks to be a Fedora thing, according to this article, from which I gleaned this information. Take a look at the man page for smrsh to learn more.

In /etc/smrsh, I wrote shell scripts that sendmail would execute. First, I wrote rt-mailgate-gen:

1
2
#!/bin/sh
/opt/rt3/bin/rt-mailgate $*

Next, after some gnashing of teeth, I figured out that I needed another script, as one of my queues had a space in its name – and $* was parsing it according to what shell wanted to do, and not what I wanted it to do. So, I wrote  second script, called rt-mailgate-gen-helpdesk

1
2
#/bin/sh
/opt/rt3/bin/rt-mailgate --queue 'help desk' --action correspond --url http://my.rtserver.com/rt3

/etc/aliases

OK, now let’s add the alias for to root.access@my.rtserver.com email address. Edit /etc/aliases using your favorite text editor (or mine, which is vim), and add lines for the root.access alias:

root.access: "|rt-mailgate-gen --queue 'rootAccessAlerts' --action correspond --url http://my.rtserver.com/rt3"
root.access-comment: "|rt-mailgate-gen --queue 'rootAccessAlerts' --action comment --url http://my.rtserver.com/rt3"

Once saved, run the newaliases command so sendmail knows about the .. uhh … new aliases.

All done!