Submitted by Eric Weik on Wed, 03/24/2010 - 11:24.
Hi Andre,
Yes, you can implement this in any theme. Add the
function THEME_preprocess_page(&$vars, $hook) {} code from my example to your template.php (replacing THEME with your theme name). It calls a Zen theme function called zen_id_safe(), so you'll need to implement this in your theme as provided by the Zen theme (it just makes sure that the id output conforms to W3C specifications for ID attributes).
If I were you, I would download the Zen theme and open up zen/zen/template.php, and simply copy and paste the zen_id_safe function declaration into your theme's template.php. While it is open, poke around and see how the Zen theme does things. Even when I am doing theme development "from scratch", I often pull in parts of the Zen theme as recipes. It does a number of useful things.
Or if you want, you can just copy and paste from here:
<?php /** * Converts a string to a suitable html ID attribute. * * <a href="http://www.w3.org/TR/html4/struct/global.html#h-7.5.2" title="http://www.w3.org/TR/html4/struct/global.html#h-7.5.2">http://www.w3.org/TR/html4/struct/global.html#h-7.5.2</a> specifies what makes a * valid ID attribute in HTML. This function: * * - Ensure an ID starts with an alpha character by optionally adding an 'id'. * - Replaces any character except alphanumeric characters with dashes. * - Converts entire string to lowercase. * * @param $string * The string * @return * The converted string */ function zen_id_safe($string) { // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)); } ?>
Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.
Reply to comment
#1 Zen not required...
Submitted by Eric Weik on Wed, 03/24/2010 - 11:24.
Hi Andre,
Yes, you can implement this in any theme. Add the
function THEME_preprocess_page(&$vars, $hook) {} code from my example to your template.php (replacing THEME with your theme name). It calls a Zen theme function called zen_id_safe(), so you'll need to implement this in your theme as provided by the Zen theme (it just makes sure that the id output conforms to W3C specifications for ID attributes).
If I were you, I would download the Zen theme and open up zen/zen/template.php, and simply copy and paste the zen_id_safe function declaration into your theme's template.php. While it is open, poke around and see how the Zen theme does things. Even when I am doing theme development "from scratch", I often pull in parts of the Zen theme as recipes. It does a number of useful things.
Or if you want, you can just copy and paste from here:
<?php/**
* Converts a string to a suitable html ID attribute.
*
* <a href="http://www.w3.org/TR/html4/struct/global.html#h-7.5.2" title="http://www.w3.org/TR/html4/struct/global.html#h-7.5.2">http://www.w3.org/TR/html4/struct/global.html#h-7.5.2</a> specifies what makes a
* valid ID attribute in HTML. This function:
*
* - Ensure an ID starts with an alpha character by optionally adding an 'id'.
* - Replaces any character except alphanumeric characters with dashes.
* - Converts entire string to lowercase.
*
* @param $string
* The string
* @return
* The converted string
*/
function zen_id_safe($string) {
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
}
?>
I hope this helps! -Eric
Reply
About
Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.
Contact Details
Lancaster, VA 22503
Content Tags
Abstract B&W Celestial Clouds Drupal 6 Drupal Recipes Drupal Sites Estuary Etsy Government Grasses HDR Long Exposure Macro New Rivers Digital Orton Photoblog Photo Expedition Photoset Renderblog RGB Sketchbook Snow Storm Structure Synth Sunflow Sunset Theming Webform.module Wide Angle Zen Zen ThemingRecent comments
Popular content
Today's:
All time:
Activity Stream
Sun, 01/29/2012 - 22:31
Mon, 01/16/2012 - 10:43
Fri, 01/06/2012 - 07:54
Powered by Drupal & Genesis | Valid XHTML 1.0 Strict |
RSS Feed
© 2010 New Rivers Digital | PO Box 784 | Lancaster, Virginia 22503 | +1-804-577-8526 | Contact Form