I've created a new content type for a collection of pages that will have very similar content. To make life as simple as possible for other users, when they create a new node of this type, I'd like for the body field to be pre-populated with some content. Is there any way to do this?

Comments

WorldFallz’s picture

don't use the standard body field, setup a multiline cck text field instead, and prepopulate it with whatever you want.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

cwrstl’s picture

Guess I'm off to install the CCK! Thanks.

cwrstl’s picture

No progress....
I've installed the CCK and read through docs, watched the screencast, etc. But I'm not certain how to do what you've suggested. Can you point me in the right direction?

WorldFallz’s picture

sure... on the content type edit page, remove the "body" label-- that will take out the standard body field. Then, click the "add field" tab to add a cck field. Give the new field a label (like "custom_body" or something), select the "text field" radio button and click "create field" at the bottom of the page. Specify the number of rows (lines) you'd like text box then click "default value" and enter whatever you want as the initial value for the field. In the "data settings" fieldset select whether you want users to be forced to enter plain text or filtered text with an input format. Click "save" and you're done.

sounds complicated, but it's not-- once you do it one time you'll be fine.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

cwrstl’s picture

OK. That's starting to make sense, and appears to work fine for text. Thanks much.
To complicate matters though, I have a little bit of PHP that I want to use to fetch some content from another URL, and I'd like this to be my default content. However, it looks like the text field always wants to use the editor, which loses much of the code, and the option to use PHP looks it wants something more involved than what I'm doing.

What I've done in a standalone page is use the PHP code input format, and put this in the body:

$url = "http://www.somedomain.com/some_page";
$string = file_get_contents($url);
$pattern = '/\<h1.+h1\>/';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);

Any ideas?

WorldFallz’s picture

did you see the instructions directly below the php box? ;-)

The code there needs to be in the following format:

<?php
$string = "THIS IS THE DEFAULT TEXT.";
return array(0 => array('value' => $string));
?>

WITHOUT the php tags.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

cwrstl’s picture

I saw the instructions for PHP. And I can manage to put some PHP code in there that gives me some results.

But what I want to do is actually have code shown as the default. Each new page I make in that content type will then just have a minor tweak made to that code as needed. In other words, I want the string that's returned to be a chunk of PHP code. Am I just looking at having to escape a lot of characters in the string assignment to make this work?

WorldFallz’s picture

ahhhh.... that's a horse of a different color. If you leave out the php tags, you can just type it in the default value text box (don't even use the php option).

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

claudio.lente’s picture

Thanks,

isnt not complicated... thanks.

sidharth_k’s picture

But even if you use a multiline text field, you will never be able to remove the body field from a custom made type right? So doesn't totally solve the issue does it?

What if you want the body field to be pre-populated?

WorldFallz’s picture

...you will never be able to remove the body field...

Sure you can... right on the create content type form it says:

To omit the body field for this content type, remove any text and leave this field blank.

I prepopulate the "body" field all the time this way. Works great.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

sidharth_k’s picture

Cheers, Sidharth

cwrstl’s picture

Long time to get back to this....
If I understand what you're suggesting correctly, it would then be up to the page author to add the php tags to the code when they create the page, correct?