0

Is there a way to use the theme() function to process an array of paragraphs, in a fashion to how theme('item_list', $theme_args) works?

If there is not a way using the theme function, what then is the "preferred" way to create a render array for an array of paragraphs?

1 Answer 1

1

There isn't a 'preferred' way, or built in function, to render an array of paragraphs. You could do it like this:

$build = array(
  'p1' => array(
    '#markup' => 'Something',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  ),
  'p2' => array(
    '#markup' => 'Something else',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  ),
);

Or this:

$build = array(
  'p1' => array(
    '#markup' => '<p>Something</p>',
  ),
  'p2' => array(
    '#markup' => '<p>Something else</p>',
  ),
);

Or you could build a theme function which takes an array of paragraphs and builds up an HTML string. Or you could use some variation of implode(), or a simple loop, and so on.

It really depends on how you want to approach it, there are several equally valid ways to solve that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.