1

I am theming an admin page & I require to load/render admin forms in page.tpl.php file.
The final output should be somehow like the attached screenshot. Scroll below to see screenshot & code written in page.tpl.php.

<h1 class="page-title">Admin Page</h1>
<div class="content-left">
  <!--load list of all contents("/admin/content") -->
  <?php print drupal_render(drupal_get_form('node_admin_content')); ?>
</div>
<div class="content-right">
  <!-- add new content form here "/node/add/page") -->
  <?php print drupal_render(drupal_get_form('page_node_form')); ?>
</div>

enter image description here

I was searching for this solution & I came across this "print drupal_render()". Please suggest best solution for this. I have render same kind of pages in other tpl.php files.

enter image description here

1 Answer 1

0

It is recommended to render the forms either in preprocess function or in the custom module. Example of rendering the form in preprocess function:

function MYTHEME_preprocess_page(&$variables) {
  // Assigning node_admin_content form to the variable.
  $node_admin_content = drupal_render(drupal_get_form('node_admin_content'));
  $variables['node_admin_content'] = $node_admin_content;

  // Assigning page_node_form form to the variable.
  $page_node_form = drupal_render(drupal_get_form('page_node_form'));
  $variables['page_node_form'] = $page_node_form;
}

Now to render this form in page.tpl.php:

<h1 class="page-title">Admin Page</h1>
<div class="content-left">
  <!--load list of all contents("/admin/content") -->
  <?php print $node_admin_content; ?>
</div>
<div class="content-right">
  <!-- add new content form here "/node/add/page") -->
  <?php print $page_node_form; ?>
</div>
8
  • Thanks Ankit, I'll try this. I am not sure if 'node_admin_content' & 'page_node_form' are correct. I took these for respective form id as an example. Commented Oct 17, 2013 at 5:59
  • @SureshAlagarYeah I have provided as an example, if you are not sure about the form id than you can dpm (if devel module installed) and check it Commented Oct 17, 2013 at 6:23
  • Hi Ankit, I found that the id name are correct & I've implemented this preprocess function in template.php file. But I am shown some error message "Notice: Undefined variable: node_admin_content in include()" in page.tpl.php Commented Oct 17, 2013 at 15:45
  • @SureshAlagar Have you cleared the cache?, otherwise $node_admin_content and $page_node_form should provide the result in page.tpl.php if the formid's are correct Commented Oct 17, 2013 at 16:34
  • @SureshAlagar Can you once check if the error is: Notice: Undefined index: node_admin_content in drupal_retrieve_form(), if that is the case than the issue is of the form id Commented Oct 17, 2013 at 16:45

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.