0

I am using the following code in a custom module to get the title of the node form in the node creation form, i.e, if i add a new content of type BLOG then on top of that node_add_blog form i get a heading/title "Create New BLOG". SO for this i got a custom module from this very forum (kudos). Now i want to know how can i place the output in a specific region, say as the right sidebar.

<?php
/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */

function show_title_form_node_form_alter(&$form, &$form_state, $form_id) {
  // For the node add form.
  //<pre
  //<?php /** print_r($form);*/?>
  //</pre>
  //<?php
  if (!$form['nid']['#value']) {
    // Add "new" to the page title.
    $node_types = node_type_get_names();
    var_dump($node_types[$form['#node']->type]);
    drupal_set_title(t('Create new @type', array('@type' => $node_types[$form['#node']->type])));
   echo "Create"." ".$node_types[$form['#node']->type];
   ;
  }

Regards

  • i don't think you can do so because you are altering a form, so the changes will only be reflected in that form. Think something like to put a altered node title in some region. – nit3ch Apr 23 '13 at 16:08
  • So are you saying you're actually trying to display this in a block that's distinct from the node you're looking at? – Boriana Ditcheva Apr 23 '13 at 16:15
  • @Boriana ...no i dont want to put it some where distinct from that node but in a different region in that node itself – user145078 Apr 24 '13 at 4:08
1

If some variable you are looking for isn't available in the scope of your hook, there is a good chance that you are doing it wrong.

Title of the page can be accessed in your theme's page.tpl.php file (or its variants). You can use a hook_preprocess_page() in your template.php file and populate a new variable if the path matches (node add forms have node/add path) so you can put it in the appropriate sidebar in the page.tpl.php.

You cannot control stuff to be shown in the page with a form_alter hook. For Drupal 7, you could use hook_page_alter() or hook_page_build() to inspect and set sidebar contents.

For an example:

template.php:

function mytheme_preprocess_page (&$variables) {
  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) && isset($vars['page']['content']['system_main']['nid'])) {
    $variables['sidebar_title'] = t('Create new @type', array('@type' => arg(2)))
  }
}

Now, print the sidebar title in your page.tpl.php's appropriate div.

if (isset($sidebar_title)) {
  print $sidebar_title;
}

Drupa.org article: Setting up variables for use in a template (preprocess and process functions)

|improve this answer|||||

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.