By harper1983 on
I just created a new content type and would like to have the body filled with a default value. How do you do that??
I just created a new content type and would like to have the body filled with a default value. How do you do that??
Comments
you made it?
Hi, have you found a way to do this?
Hi there, using template
Hi there,
using template functions and form api this may be achieved. First locate your appropiate template.php within your current theme folder. Add a new function:
This piece of code by itself does nothing yet, so let's take a look at the INTERESTING PART. If you've ever worked with form API before you might think of trying something like this:
However, it doesn't work, probably because of the javascript functions running on #after_build.
But we can use javascript, too, to populate the body field. We're just using the #suffix of the bodyfield by adding:
Ét voilà: Upon creating a new node the body field is prepopulated with whatever text you entered in the code line above.
Soon you will notice, though, that this also works when editing existing nodes and thus is replacing original text by this line. So we'll need to check if the body's default value is set or not:
Now, the default text is only inserted upon creating new nodes and not when editing existing ones (as long as they contain text).
Well now, you might think, this is working alright, but I want the default text for special content types only. So, you'll need another check before taking any actions. Let's say, only pages shall have a default text inserted, then the INTERESTING PART would look like this:
That way, you are able to set default texts for each content type there is. All you need is the machine readable name of each content type and this function (see whole function below).
While this might not the optimal solution it works quite well for me, so I thought I'd share it.
Best,
Paul
DefaultTextForNode
The following module is able to do that http://drupal.org/project/DefaultTextForNode