I'm creating quicktabs using drupal_render(quicktabs_build_quicktabs($qtname, $overrides ,$content_tabs)). A few of the tab titles I'm creating have apostrophes, which are incorrectly rendering as html entities. So if the title of a tab is Women's Magazine, it's displaying as:
Women's Magazine
Since the views style plugin for quicktabs uses the same quicktabs_build_quicktabs() function, I created a test view with the quicktabs style and it rendered with the html entity, not the apostrophe. Also, I've tested the quicktabs_build_quicktabs function with print_r, outputting just the array, and that returns the tab title with the apostrophe correctly, so I believe this is an issue with drupal_render(). Has anyone else seen this issue?
Full code below:
//Get the Node Object
$all_tabs = $content['group_all_tabs']['group_tab1']['field_tabs']['#object'];
$content_tabs = array();
//Run a Loop to get the tabbed information -currently limited to 6 tabs
for ($i=1;$i<7;$i++) {
//Proper set-up for displaying a field in a node using the field api
$node = node_load($all_tabs->nid);
$title_field = field_get_items('node', $node, 'field_tab'.$i.'_title');
$title_output = field_view_value('node', $node, 'field_tab'.$i.'_title', $title_field[0]);
$tab_title = render($title_output);
//Check to see if the tab has a title, if not, do not display
if ($tab_title != '') {
//The first body field has a different name, so check for that
if ($i == 1) {
$body_field = field_get_items('node', $node, 'field_tabs');
$body_output = field_view_value('node', $node, 'field_tabs', $body_field[0]);
$tab_body = render($body_output);
}else {
$body_field = field_get_items('node', $node, 'field_tab'.$i.'_body');
$body_output = field_view_value('node', $node, 'field_tab'.$i.'_body', $body_field[0]);
$tab_body = render($body_output);
}
//Finally add the tabs to the main array
$content_tabs[] = array(
'title' => t($tab_title),
'contents' => array('#markup' => t("$tab_body")),
'weight' => $i,
);
}
}
//Render the created quicktab programmatically
$qtname = 'ministry-tabs';
$overrides = array('style' => 'Sky', 'sorted' => TRUE, 'ajax' => FALSE);
//print_r(quicktabs_build_quicktabs($qtname, $overrides ,$content_tabs));
$full_qt = quicktabs_build_quicktabs($qtname, $overrides ,$content_tabs);
print drupal_render($full_qt);
Comments
Comment #1
kaynen commentedI figured out the issue with my above code. It turns out that if there is an html entity in a string that's printed using print_r() or var_dump(), the html entity will not render- that was news to me. Anyway, the fix for me was that this line:
'title' => t($tab_title),needed to be changed with this:
'title' => html_entity_decode($tab_title, ENT_QUOTES),Also, this issue needs to be fixed in quicktabs_style_plugin.inc for the quicktabs view style. Here's code that will work, starting at line 121:
Hope this helps someone!
Comment #2
Frederic wbase commentedFix works like a charm, i had the same issue in quicktabs created by views. When will this be committed?
Comment #3
druvision commentedThis is almost a duplicate of Tab titles shows escaped HTML tags, which takes a more generic approach to the issue.
Comment #4
manila555 commentedExcellent! This was very helpful.
Thanks for posting
Comment #5
white_pawn commentedMy issue is somewhat similar. I'm using Quick Tabs to create a mini-calendar of a sort, and I need my tab titles to be dynamic and contain some HTML markup. So, first I load the existing Quick Tab instance ("mycalendar") into an object:
Then, I change the tab titles, e.g.:
But, no matter what I do, when I render the object by calling
drupal_render($quicktabs), the HTML markup in the title persists as plain text.Any help would be much appreciated.
Comment #6
white_pawn commentedSOLVED:
Comment #7
iwhy commentedComment #8
iwhy commentedhi, white_pawn, where should i place this code?
Comment #9
kikepuebla commentedin include/quickstyle_style_plugin.inc
search function render (by default on line 82)
before function do $output = drupal_render($quicktabs); put it
for ($i=0; $i < sizeof($quicktabs['content']['content']['tabs']['tablinks']); $i++) {
$quicktabs['content']['content']['tabs']['tablinks'][$i]['#options']['html'] = TRUE;
}
This ennabled html for all your tabs
Comment #10
operations commented@kikepuebla this worked for me but I noticed that it is not commited to dev version yet. Thanks anyways!
Comment #11
dooug commentedThe solution in #9 only applies to a the quicktab Views plugin. I didn't test it and can't comment on its validity.
However, I needed a general solution to make the HTML tags render in tab titles. I was able to override this theme function: theme_qt_quicktabs_tabset() and enable HTML for the tab links. This is probably preferred because it doesn't require patching the module. This is the code I used that works for the "quicktabs" style quicktabs:
Comment #12
dooug commentedMarking as duplicate with #894746: Allow HTML in tab titles
Comment #13
bzitzow commented+1 for solution in comment #11
Updated a site from quicktabs 7.x-3.4 to 7.x-3.6 and the tab title's were printing the html that was saved in the cms as strings. This was the output of an existing view.
I overrode the original theme method (here: http://drupalcode.org/project/quicktabs.git/blob/refs/heads/7.x-3.x:/qui...) as suggested and it rendered the html - just like the previous behavior in 7.x-3.4
Comment #14
raffi commented#11 worked perfectly
Comment #15
jessZ commentedI have quicktabs 7.x.36 installed and drupal 7.33. double quotation marks, single quotation marks and ampersands in NODE TITLES not the tab titles of Quicktabs are being converted to html entities. (turn quicktabs module off ,problem goes away. turn it on, comes back. Is this a more general case of the same problem above? I also have a Views and a lot of views related modules installed, but this is happening just with simple nodes.
Comment #16
slown commented#11 Worked very well! Thank's a lot ;-)
Comment #17
sj.suraj commentedAfter a long searching.....#11 works very fine. And it also worked with 3.8 version. Thanks a lot!