- Posts: 404
COMMUNITY FORUM
Adding HTML code into Extra Fields
- Odin Mayland
- Offline
- Platinum Member
Less
More
13 years 2 months ago #76473
by Odin Mayland
Replied by Odin Mayland on topic Adding HTML code into Extra Fields
I applied Josh's hack from this thread onto the following site: www.primocraft.com
Open up Administrator/components/com_k2/models/extrafield.php
You can always put in a die() command and print_r sections just after the variables are set so you know whats about to be saved, then adjust as needed. The below should help.
//line 32 - replaced if (!$row->bind(JRequest::get('post',JREQUEST_ALLOWHTML))) //around line 53 - replaced $objects = array (); $values = JRequest::getVar('option_value','','post','string',JREQUEST_ALLOWRAW); $names = JRequest::getVar('option_name','','post','string',JREQUEST_ALLOWRAW);
I copied and pasted a table's html, into the extrafield's textarea's html box, in the editor within a k2 item and it works perfectly. None of the code is getting stripped out. That was very wordy so here are some screenshots:
It will look like this:
And finally it will display as expected like this:
Johnno Church said:
Hi there, I am trying to insert a table into the extra field of my K2 category and find myself pulling teeth over this. I have scoured many threads and attempted many hacks with zero success. The code is stripped and displayed as plain text. I am using K2 2.4.1 just to let you know. I would really like your advice as I am not fluent with .php...Thanks in advance...
Open up Administrator/components/com_k2/models/extrafield.php
You can always put in a die() command and print_r sections just after the variables are set so you know whats about to be saved, then adjust as needed. The below should help.
//line 32 - replaced if (!$row->bind(JRequest::get('post',JREQUEST_ALLOWHTML))) //around line 53 - replaced $objects = array (); $values = JRequest::getVar('option_value','','post','string',JREQUEST_ALLOWRAW); $names = JRequest::getVar('option_name','','post','string',JREQUEST_ALLOWRAW);
I copied and pasted a table's html, into the extrafield's textarea's html box, in the editor within a k2 item and it works perfectly. None of the code is getting stripped out. That was very wordy so here are some screenshots:
It will look like this:
And finally it will display as expected like this:
Johnno Church said:
Hi there, I am trying to insert a table into the extra field of my K2 category and find myself pulling teeth over this. I have scoured many threads and attempted many hacks with zero success. The code is stripped and displayed as plain text. I am using K2 2.4.1 just to let you know. I would really like your advice as I am not fluent with .php...Thanks in advance...
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Offline
- Platinum Member
Less
More
- Posts: 404
13 years 1 month ago #76474
by Odin Mayland
Replied by Odin Mayland on topic Adding HTML code into Extra Fields
Looks like I should try this method.
Can you send me the "module in item.php code snippet" ?
mat said:
Hi Modernmagic,
Another alternative....
If this is to be the same "icon" modalizer plugin for all of the items within a category(s), and you dont want to have to manually add it to every item in the category individually.....
Create/edit an override template for the category, add the code to run a Custom Code module ( from Joomlaworks) within the k2 item template, this module can execute plugins, and PHP - it has worked on all the plugins that I have needed to run so far....so in theory should work for this situation too.. ;)
Set the module to display in all pages or just the menu link for the required category...
And all items within the category now have the icon and the plugin as required - and only 1 file to edit : item.php and 1 module to maintain/edit
Let me know if you need the module in item.php code snippet....
Can you send me the "module in item.php code snippet" ?
mat said:
Hi Modernmagic,
Another alternative....
If this is to be the same "icon" modalizer plugin for all of the items within a category(s), and you dont want to have to manually add it to every item in the category individually.....
Create/edit an override template for the category, add the code to run a Custom Code module ( from Joomlaworks) within the k2 item template, this module can execute plugins, and PHP - it has worked on all the plugins that I have needed to run so far....so in theory should work for this situation too.. ;)
Set the module to display in all pages or just the menu link for the required category...
And all items within the category now have the icon and the plugin as required - and only 1 file to edit : item.php and 1 module to maintain/edit
Let me know if you need the module in item.php code snippet....
Please Log in or Create an account to join the conversation.
- matthew turner
- Offline
- Senior Member
Less
More
- Posts: 66
13 years 1 month ago #76475
by matthew turner
Hi Modernmagic,
<!-- Replace "incontent" with the name of the module you want to insert --> <?php if(JModuleHelper::getModules('incontent')): ?> <?php foreach (JModuleHelper::getModules('incontent') as $module) {echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));} ?> <?php endif; ?>
Replied by matthew turner on topic Adding HTML code into Extra Fields
Hi Modernmagic,
<!-- Replace "incontent" with the name of the module you want to insert --> <?php if(JModuleHelper::getModules('incontent')): ?> <?php foreach (JModuleHelper::getModules('incontent') as $module) {echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));} ?> <?php endif; ?>
Please Log in or Create an account to join the conversation.
- Ali
- Offline
- New Member
Less
More
- Posts: 8
3 years 2 months ago #179404
by Ali
if i added this code to my K2 i can use HTML code in my Extra Fields ?
for examle i want add something like this
choice multi text
<a href="www.aaaa.com"> Test
but not work he delete HTML and hold just Test ...
Replied by Ali on topic Adding HTML code into Extra Fields
after many years :)I applied Josh's hack from this thread onto the following site: www.primocraft.com
Open up Administrator/components/com_k2/models/extrafield.php
You can always put in a die() command and print_r sections just after the variables are set so you know whats about to be saved, then adjust as needed. The below should help.
//line 32 - replaced if (!$row->bind(JRequest::get('post',JREQUEST_ALLOWHTML))) //around line 53 - replaced $objects = array (); $values = JRequest::getVar('option_value','','post','string',JREQUEST_ALLOWRAW); $names = JRequest::getVar('option_name','','post','string',JREQUEST_ALLOWRAW);
I copied and pasted a table's html, into the extrafield's textarea's html box, in the editor within a k2 item and it works perfectly. None of the code is getting stripped out. That was very wordy so here are some screenshots:
It will look like this:
And finally it will display as expected like this:
Johnno Church said:
Hi there, I am trying to insert a table into the extra field of my K2 category and find myself pulling teeth over this. I have scoured many threads and attempted many hacks with zero success. The code is stripped and displayed as plain text. I am using K2 2.4.1 just to let you know. I would really like your advice as I am not fluent with .php...Thanks in advance...
if i added this code to my K2 i can use HTML code in my Extra Fields ?
for examle i want add something like this
choice multi text
<a href="www.aaaa.com"> Test
but not work he delete HTML and hold just Test ...
Please Log in or Create an account to join the conversation.