I have a custom module in Drupal 7 that creates nodes. I want a custom css stylesheet (customstyle.css) applied when one of the nodes created by my custom module is rendered, but only when one of the nodes created by my custom module is rendered.
The simple solution (adding stylesheets[all][] = customstyle.css to my custom module’s .info-file) applies the style sheet to all pages, including pages containing nodes not created by my custom module. I do not want that.
I assume that “nodes created by my custom module” means that they have some special node type. If so, you can implement
hook_node_view()in your module and then calldrupal_add_css()based on the node type or any other property: