I went to try and look for how to add css and js from the newb contrib module developers perspective in the API docs and couldn't find it. I think we need to update the render api documentation (which talks about #markup) to include a reference to the #attach attribute.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

metzlerd’s picture

Title: Make #attach more prevalent in render api docs » Make #attached more prevalent in render api docs
metzlerd’s picture

Here's a stab at pulling just the basics in with refrence to the code that does the work.

metzlerd’s picture

Status: Active » Needs review
metzlerd’s picture

Minor corrections...

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

The latest patch looks good! Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2fdeb8f and pushed to 8.0.x. Thanks!

diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php
index 2bb477d..7a2181d 100644
--- a/core/modules/system/theme.api.php
+++ b/core/modules/system/theme.api.php
@@ -287,9 +287,9 @@
  * @section sec_attached Attaching libraries in render arrays
  *
  * The #attached property allows loading of CSS, JavaScript, libraries or custom
- * types. Specify an array of type => value pairs, where the type (most often 'css',
- * 'js', or 'library') determines the loading technique and the value provides the
- * options specified to the loader function. Example:
+ * types. Specify an array of type => value pairs, where the type (most often
+ * 'css', 'js', or 'library') determines the loading technique and the value
+ * provides the options specified to the loader function. Example:
  * @code
  * $form['#attached']['css'] = array(
  *   drupal_get_path('module', 'ajax_example') . '/ajax_example.css',

Re-flowed the comment to adhere to the 80 character width rule.

  • alexpott committed 2fdeb8f on 8.0.x
    Issue #2359561 by metzlerd: Make #attached more prevalent in render api...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.