How to add a new field to the CMS
- Apply the changes mentioned in this how-to at your own risk.
- You must have a basic understanding of php, html and vbulletin. - This is a how-to for vb4.1, and may not work on previous versions. Everywhere you see FIELDNAME, replace it with your field name (must not contain spaces). 1. Create a new field in the cms_node table. 2. If you run vB 4.1.9 or lower , open packages\vbcms\item\content.php and find: PHP Code:
PHP Code:
3. Go to the template vbcms_edit_publisher. At the bottom of the template, before these lines: HTML Code:
</div> HTML Code:
<div class="blockrow" > Go to your ACP --> Plugins & Products --> Add New Plugin. Hook Location: vbcms_article_save_start. PHP Code: PHP Code:
The following steps have been written by Lynne, thank you :) 5. To get the field to spit out, you must add it to the vbcms_content_article_page somewhere (this is rough, you'll have to add your own class/styling). HTML Code:
<div>Custom Field:{vb:raw FIELDNAME}</div> PHP Code:
PHP Code:
PHP Code:
PHP Code:
That's it, you're done. |
Thank you! I'll have to try this out. :)
|
I tried that for 3 fields (instead of one) and I can't get any of the data submitted to save into the database... some troubleshooting of the above code might be needed... have you tried this yourself?
|
Quote:
|
Quote:
content.php: Code:
$geturl_text = vB::$vbulletin->db->query_first("SELECT url_text FROM " . TABLE_PREFIX . "cms_node WHERE nodeid = " . $this->nodeid); article.php: Code:
protected $content_properties = array( vbcms_content_article_inline template added this: Code:
<div class="blockrow"> Code:
{vb:raw editor} plugin with vbcms_article_populate_start hook: Code:
$view->url_text= $this->content->geturl_text(); and plugin with vbcms_article_save_start hook: Code:
vB::$vbulletin->input->clean_array_gpc('r', array( As I said, the fields show up just fine, but when I enter anything into them and click Save or Apply, the values are not shown. They are correctly saved in the mysql, but are not being shown in the Edit Article page under those fields when the changes to the article are saved. |
I have tried this and it works fine for me. Have you tried spitting out your last query to see if it is correct?
This is incorrect: PHP Code:
PHP Code:
|
Doh!
Obvious mistake. That was it, in a way... Now, the problem I have is if I put those fields in "vbcms_edit_publisher" template, they show up just fine and work ok. But if I put them in "vbcms_content_article_inline" template - no go, they don't show the values at all, even though they save them properly. And I'd rather have those extra fields in vbcms_content_article_inline, below the actual content box instead of in vbcms_edit_publisher which adds them into the right-hand column which makes that long column even longer now... Thoughts? Maybe this has something to do with the hooks? |
If you want them in other templates, you must write a plugin to register them for use in the other template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
|
Quote:
Geez... I just spent almost an hour going through it and trying it out without any success. Tsk, why does this have to be so darn complicated... Hmm, how can I extend that $pub_view array to be available to other templates, not just vbcms_edit_publisher (as defined in content.php) in an easier manner... --------------- Added [DATE]1295989658[/DATE] at [TIME]1295989658[/TIME] --------------- It seems that I am having some issue with spitting out the value in the front-end as well... adding that code to vbcms_content_article_page prints out nothing. Seems the root of the problem is $view->FIELDNAME = $this->content->getFIELDNAME(); in the plugin attached to vbcms_article_populate_start... as if I change that $view->FIELDNAME value to a constant, I get a value out on the front-end and in all the other templates (weird). If I leave it as $this->content->getFIELDNAME(), it ends up blank. |
Ah yes, steps 5 through 9 were written to add the fields to the article page. That's it. If you need it on another page, you'd have to probaby do all those steps on another page. Perhaps someone else will look into that part and post it.
|
All times are GMT. The time now is 08:39 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|