Posted by mario_p7 on January 27, 2013 at 3:19am
Hi,
I was wondering if anyone can help me with adding an attribute to an element for which the HTML is auto generated by drupal, in the HTML of my page.
Basically from what I can see, there is a lot of the HTML output of the page that drupal auto generates. I want to know how I can add something to that generation. I. e. access an element (for instance an anchor or a div) and add an attribute to it.
Thanks,
Mario
Comments
=-=
investigate drupal preprocess functions and overriding theme functions. Else you will need to be more specific about what you are looking to do.
Adding the attribute
Hi,
Thanks for the tip. In this specific instance I have this code in my page.tpl.php which themes the $secondary_menu. It generates a series of things among which, anchors for "Log in" and "register". From what I can see the code below has an array of "attributes" inside the links.
<?phpif ($main_menu || $secondary_menu):
?>
<?phpprint theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Secondary menu')));
?>
<?phpendif;
?>
I want to add one more tag inside the anchor generated by this.
This however is only one specific instance of my bigger question. Is there a straightforward way to access from inside any of the .tpl.php files the HTML structure of the page? I mean how does it work? Is there a specific function per page or node that I have to override to modify some of the output HTML generated by drupal?
Hope I have made clearer what I mean,
Thanks,
Mario
Hey, Not exactly sure what
Hey,
Not exactly sure what you're wanting the output to be, but you might look at the theme_menu_link function to override in your template.php file. That would allow you to override what html is output by a menu link.
Most themed output is generated by different functions. If you can find which function outputs the html, you can make our own version in your template.php to override it.