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

kaynen’s picture

I 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:

$tabs[] = array(
          'title' => html_entity_decode($title, ENT_QUOTES),
          'contents' => array('#markup' => $contents),
        );
      }

      // If not grouped, there's just one set of rows that we loop through.
      else {
        foreach ($rows as $index => $row) {
          $title = $this->get_field($index, $this->options['tab_title_field']);
          $tabs[] = array(
            'title' => html_entity_decode($title, ENT_QUOTES),
            'contents' => array('#markup' => $row),
          );
        }
      }

Hope this helps someone!

Frederic wbase’s picture

Fix works like a charm, i had the same issue in quicktabs created by views. When will this be committed?

druvision’s picture

This is almost a duplicate of Tab titles shows escaped HTML tags, which takes a more generic approach to the issue.

manila555’s picture

Excellent! This was very helpful.

Thanks for posting

white_pawn’s picture

My 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:

$quicktabs=quicktabs_build_quicktabs( 'mycalendar', $overrides);

Then, I change the tab titles, e.g.:

$quicktabs['content']['content']['tabs']['tablinks'][0]['#title'] = "Day 1 <br /> October ".$day;

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.

white_pawn’s picture

SOLVED:

$quicktabs['content']['content']['tabs']['tablinks'][0]['#options']['html'] = TRUE
iwhy’s picture

iwhy’s picture

hi, white_pawn, where should i place this code?

kikepuebla’s picture

in 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

operations’s picture

@kikepuebla this worked for me but I noticed that it is not commited to dev version yet. Thanks anyways!

dooug’s picture

The 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:

/**
 * Overrides Theme function to output tablinks for classic Quicktabs style tabs.
 */
function YOUR_THEME_NAME_qt_quicktabs_tabset($vars) {
  $variables = array(
    'attributes' => array(
      'class' => 'quicktabs-tabs quicktabs-style-' . $vars['tabset']['#options']['style'],
    ),
    'items' => array(),
  );
  foreach (element_children($vars['tabset']['tablinks']) as $key) {
    $item = array();
    if (is_array($vars['tabset']['tablinks'][$key])) {
      $tab = $vars['tabset']['tablinks'][$key];
      $tab['#options']['html'] = TRUE; // Added this to override to allow HTML in titles.
      if ($key == $vars['tabset']['#options']['active']) {
        $item['class'] = array('active');
      }
      $item['data'] = drupal_render($tab);
      $variables['items'][] = $item;
    }
  }
  return theme('item_list', $variables);
}

dooug’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Marking as duplicate with #894746: Allow HTML in tab titles

bzitzow’s picture

+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

raffi’s picture

#11 worked perfectly

jessZ’s picture

I 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.

slown’s picture

#11 Worked very well! Thank's a lot ;-)

sj.suraj’s picture

After a long searching.....#11 works very fine. And it also worked with 3.8 version. Thanks a lot!