1) Open superfish.module file.
2) Scroll down to theme_superfish_build method.
3) Add your new logic to the last section of the method where there is concatenation of the output html.
My logic was this:
$pattern = '/\S+\.(png|gif|jpg)\b/i';
if(preg_match($pattern, $menu_item['link']['title'], $matches) > 0)
{
$output['content'] .= '<a href="'.url($menu_item['link']['link_path']).'">'.preg_replace($pattern,'<img alt = "' . $menu_item['link']['title'] . '" src = "' . url($matches[0]) . '" />',
$menu_item['link']['title']).'</a>';
}
else
{
$output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);
}
This logic transforms a url path in the title that contains an image file extension into an image tag. This worked good for my solution, but would not have worked well if all my menu items needed an image. That is because the title would be displayed in other modules such as menu block. I would have needed a much more complicated snippet to handle an entire menu.
No comments:
Post a Comment