Add a New Entry FieldNote: Revised for compatibility with MT version 2.21. I read the Movable Type forum regularly and have noticed that every now and then there is a question on how to add a new field to the Entry records. Being inquisitive by nature, I thought I would try to find out. The following is a description of the method I used; there are probably others but this seems to work. Warning: Be sure to make back up copies of your complete database directory and all the files modified... just in case. I was able to add the new field to existing entries without any difficulty but be sure to keep a copy of the database files, not just an export set. We will be working with the following files: Step 1: Add the field to the Entry object.We will be adding a field named "DisplayOrder" in this example. You can of course name the field what ever you want; just subsitute the name you want where I have used "DisplayOrder". Open the Entry.pm file and search for Add the new field name. You will need to enter it enclosed in single quotes followed by a comma. Therefore, after adding the new "DisplayOrder" field, the above lines look like: If you want to update the POD documentation at the bottom of the file, search for Save the Entry.pm file and close it. Step 2: Register the fieldEach field in a record must be "registered" to place it in the proper parsing context. Essentially, this enables Movable Type to find the field when it is needed. Open the Context.pm file and search for Enter the following line to register a handler subroutine for the new field (substitue the field name you are using for "DisplayOrder"): Now search for Note: The lines above wrap due to the display area on this page. Just make the subroutine look like the others near it. Save the Context.pm file and close it. Step 3: Enable the field in the PreviewYou only need to do this if you want your new field to display in the entry preview. Open the CMS.pm file and search for Enter the following line to make the new field available to the preview page: Now scroll down a few lines until you see: and insert an MT tag where you want the new field to display on the preview page. I put mine at the top and made it red, so my preview output description looks like: Save the CMS.pm file and close it. Step 4: Enable the field in the Entry formAlmost there! All we need to do now is to place a form field in the Entry form so you can enter something in your new field. In my case, I only want to be able to enter a small amount of text so I chose to use an input type=text field similiar to that used for the Title field. Open the edit_entry.tmpl file and search for Main Entry Text. This will get you in about the right spot. You will see something like: You should probably scan the html code to see where you want to place your new field in the form. In my case, I put it just above the Main Entry Text field. This area of the page is a two column layout so I chose to place the field name in the left column and the form field next to it in the right column. If you are using a larger field and want to use a textbox form field, you will probably want to do it like the Main Entry Text field. Play with it a little until you have the presentation you want. What I did was to insert the following lines just above the row containing the Main Entry Text field. Save the edit_entry.tmpl and close it. Now all you need to do is to include the new field you just created in a template. You can use an MT tag like Good Blogging! CommentsPost a comment |
NotesArticlesJournalFriendsPowered By |
|||
© 2002 bnsDesigns |
||||