I have a customised form template 'user-profile-edit.tpl.php' and i'm trying to add some custom variables so I can get a block of dynamic content (users current friends / requests etc) to display in the middle of the form.

I can use 'MODULE_form_user_profile_form_alter()' to add to the form but this is not ideal as they are not form items but arbitrary markup from a custom module. I'm having to hack the form structure as follows:

$form['my_custom_stuff'] = array(
    '#markup' = 'some markup',
    '#description = 'some more markup',
    '#title' = 'yet more markup',

which is not nice.

Ideally i'd like to find a way to pass variables created in 'MODULE_preprocess_page()' to the 'user-profile-edit.tpl.php'. Is this possible?

Alternatively - is there a way to add custom elements to the form array without getting 'Fatal error: Unsupported operand type'?

And, no I can't change the order of the fields - the design was signed off a long time before I got involved with this project!


1 Answer 1


Try $variables[] in your preprocess function!

 function template_preprocess_foo(&$variables) {
  $variables['foo_list'] = array(
    'list item 1',
    'list item 2',
    'list item 3',
  • I can add stuff to the $variables array but I can only access them from the page template - I need to get them in the form template
    – Bn Mk
    Commented Apr 15, 2014 at 13:16

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.