diff --git a/template.php b/template.php index 6deb89d..520f27d 100644 --- a/template.php +++ b/template.php @@ -474,3 +474,43 @@ function dewey_render_node_body($nid) { return $node->body; } +/** + * Contextually adds 960 Grid System classes. + * + * The first parameter passed is the *default class*. All other parameters must + * be set in pairs like so: "$variable, 3". The variable can be anything available + * within a template file and the integer is the width set for the adjacent box + * containing that variable. + * + * class="" + * + * If $var_a contains data, the next parameter (integer) will be subtracted from + * the default class. See the README.txt file. + */ +function ns() { + $args = func_get_args(); + $default = array_shift($args); + // Get the type of class, i.e., 'grid', 'pull', 'push', etc. + // Also get the default unit for the type to be procesed and returned. + list($type, $return_unit) = explode('-', $default); + + // Process the conditions. + $flip_states = array('var' => 'int', 'int' => 'var'); + $state = 'var'; + foreach ($args as $arg) { + if ($state == 'var') { + $var_state = !empty($arg); + } + elseif ($var_state) { + $return_unit = $return_unit - $arg; + } + $state = $flip_states[$state]; + } + + $output = ''; + // Anything below a value of 1 is not needed. + if ($return_unit > 0) { + $output = $type . '-' . $return_unit; + } + return $output; +} \ No newline at end of file