Renderable arrays versus strings

Benjamin Melançon's picture
Submitted by Benjamin Melançon on 2010, December 13 - 11:28

Tags

  • Render API
  • Drupal 7 would like you to provide all content meant for display to the user as renderable arrays (which allows changes from other parts of Drupal and potentially smart caching). It does, however, accept a plain string, and outputs that directly, and indeed Drupal core often does this.

    To mix simple strings with proper render arrays, simply use '#markup' => $raw_html; for your string

    (thanks to davereid and chx in IRC for pointing this out)

  • Explanation

  • module dev chapter
  • Book element

  • Gotcha