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

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>
  • 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. – Suresh Alagar Oct 17 '13 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 – Ankit Agrawal Oct 17 '13 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 – Suresh Alagar Oct 17 '13 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 – Ankit Agrawal Oct 17 '13 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 – Ankit Agrawal Oct 17 '13 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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