Posted by designguru on December 4, 2008 at 3:52pm
Hey all,
I've been searching for days for an approach that actually works - its a shame that this isn't a simple option when editing each node type from the regular drupal admin side but...
...I'm looking for a snippet to throw into my template.php which will let me specify a custom title atop a node submission/editing page per content type; so instead of 'Create Tomato' I could specify say 'Throw a tomato at us' when a user is looking @ the node/add/tomato page.
I'd love to know if there's an approach to use for both drupal 5 and 6 - if they aren't the same then I would super appreciate snippets for both... I'm surprised to not have found this info anywhere in the handbook...
Thanks,
q./
Comments
theme your node form
as per http://drupal.org/node/68999 [hehe, toot-toot!] you can set the title in your form theme.
so in your template.php file, define (or extend), replacing as appropriate:
function phptemplate_node_form($form) {switch($form['type']['#value']) {
case 'my_node_type':
$title = empty($form['nid']['#value']) ? 'Add a new custom node' : 'Edit a new custom node';
drupal_set_title($title);
break;
}
return drupal_render($form);
}
This will allow you to redefine all node edit form titles actually. You'll have to modify slightly if you don't want to modify the title when you're editing existing nodes.
Thanks to Andre Molnar for setting me on the one and true drupal way for this solution.
relocates buttons
Using this method in Drupal 6, my title is correctly changed by my submit and preview buttons get relocated to the top of my form. I'm not sure why that's happening, but any ideas...
odd thing...
odd thing... exactly the same happened to me.
devilish details
If you check out the node module, you'll see that there's already a theme_node_form. So the above solution replaces that theme, which causes unexpected side-effects (including the relocating of buttons as observed in other comments).
So, to fix the above solution, replace that last
return drupal_render($form)line with
return theme_node_form($form)so that the usual fix ups to the form are done (see comments in the node.page.inc file to see all of what theme_node_form does).
Many thanks -- here's a variation for forum topics
I was using this solution for customizing the node create page for a forum topic, and I wanted to include the specific forum topic name (which is a taxonomy term) into the title text. After much struggle, I hit on the trick of using arg() to get the term id (in this case the path is node/add/forum/id, so it was arg(3)) and then calling taxonomy_get_term with it. Here's the result:
function phptemplate_node_form($form) {switch($form['type']['#value']) {
case 'forum':
$forum_term = taxonomy_get_term(arg(3));
$title = empty($form['nid']['#value']) ? 'Add a new ' . $forum_term->name . ' posting': 'Edit a ' . $forum_term->name . ' posting';
drupal_set_title($title);
break;
}
return drupal_render($form);
}
Laurance Rosenzweig
rosetwig@gmail.com
215 859 0596
Module solution
Hi,
I've written a module to address this
http://www.practicalweb.co.uk/blog/09/05/25/module-make-title-nodeadd-pa...
Sponsored by
http://www.consultanddesign.net/
I've applied for a Drupal CVS account to upload this
Sean Burlington
www.practicalweb.co.uk
Sean Burlington
www.practicalweb.co.uk
Drupal CVS
Any luck with the Drupal CVS account?
for those who stumble across
i'm quite sure this is not the best approach, but it got me quickly back to a working theme after moving from 5.x to 6.x.
for several content types, we have a parent-child relationship (e.g. school assignment/student submission to that assignment). for these types of content, we display the form side by side with its parent. in 5.x we used this in the template.php file:
function phptemplate_node_form($form) {switch ($form['#node']->type) {
case 'self_essay':
return _phptemplate_callback('node-add-tasksubmit', array('form' => $form));
default:
return theme_node_form($form);
}
}
for 6.x we have moved to this:
function phptemplate_node_form($form){
switch ($form['#node']->type) {
case 'self_essay':
return theme_render_template(path_to_theme().'/node-add-tasksubmit.tpl.php', array('form' => $form));
default:
return theme_node_form($form);
}
}
i tried getting preprocess functions to work, and they were great for displaying nodes, but i could not figure out how to customize the node/add node/edit using that approach.
here's the code for the node-add-tasksubmit.tpl.php the hairy sql is used to figure out what node to display on the left:
<!-- start node-add-tasksubmit.tpl.php --><div id='left5050'>
<?php
if (arg(2) == 'edit') {
$editnid = arg(1);
$query = <<<SQL
select field_gta_task_nid
from content_type_task_assignment_group, content_field_ems_assignment
where content_field_ems_assignment.nid = '$editnid' and
content_field_ems_assignment.field_ems_assignment_nid = content_type_task_assignment_group.nid
SQL;
}
else{
$assignmentnid = arg(3);
$query = "select field_gta_task_nid from content_type_task_assignment_group where nid = '$assignmentnid'";
}
$task = db_result(db_query($query));
$node = node_load($task);
?><h3>
<?php print $node->title; ?>
</h3>
<?php
print node_view($node, false, true, false);
?>
</div>
<?php
$submitform = "<div id='right5050'><h3>Please complete this form to submit your assignment</h3>";
$submitform .= drupal_set_title('');
$submitform .= drupal_render($form);
$submitform .= "</div>";
print $submitform;
?>
<!-- end .tpl.php -->
Hi, I'm looking for custom
Hi, I'm looking for custom node/add page titles.
1. Put the code in template.php
2. node-add-tasksubmit.tpl.php
but where i set custom titles for different content types ?
example:
content-type1 = blablabla[title]
content-type2 = [title]blablabla
Another solution
Actually, i'm using this code display in an active block:
<?phpdrupal_set_title("".t('Add xxx')." :");
?>
This method works very well, but you have to create one block per node type...
@Junro How can I hide the
@Junro How can I hide the original title displayed by default?
Hello, Now, what the best
Hello,
Now, what the best approach for D6?
Thanks
Hello, I try this code in my
Hello, I try this code in my template.php file but it doesn't work
<?phpfunction phptemplate_node_form($form) {
switch($form['type']['#value']) {
case 'my_node_type':
$title = empty($form['nid']['#value']) ? 'Add a new custom node' : 'Edit a new custom node';
drupal_set_title($title);
break;
}
return drupal_render($form);
}
?>
I had only replace 'my_node_type'
Is this code still working in D6?
It doesn't work in mine either
Not sure why, I gave this in my template.php abd it doesn't work either.
function phptemplate_node_form($form) {$title = 'TEST TITLE';
drupal_set_title($title);
return theme_node_form($form)}
Quality Digital Design & Development Consultancy Newcastle
re
it’s good to see this information in your post, i was looking the same but there was not any proper resource.
assignment | lab report writing help
Custom module
here is a snippet of how to achieve that in you custom module
function mymodule_form_alter(&$form, $form_state, $form_id) {if($form_id == 'mynodetype_node_form'){
drupal_set_title('My new title');
}
}
Drupal in the Amazon Jungle
Title not changed when validate
Hi,
drupal_set_title('My new title') is working fine when the form loads.
But when form submits and if there are any validation errors, the title is reverted back instead of "My new title".
Please help.
--thanks
Here's my roundabout way of
Here's my roundabout way of dealing with that. I added an additional validation handler that sets the page title to the same thing as in my form_alter. Not pretty, but it works:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'mynodetype_node_form_node_form') {
$form['#validate'][] = 'mymodule_validate';
drupal_set_title(t('My New Title'));
}
}
function mymodule_validate($form, &$form_state) {
drupal_set_title(t('My New Title'));
}
customizing node's add form
http://drupal.org/node/729322