0

I'm trying to add a line break to a tooltip in my twig template. I used this: Add line break to tooltip in Bootstrap 3 solution and added the code to my table where I'd like to apply this for one column:

<td {% if item.uploadprofiles %} 
data-toggle="tooltip" 
data-html="true" 
title={% for up in item.uploadprofiles %} "Upload Profile ID: {{ up.id }} <br> Upload Profile Name: {{ up.name }}" {%  endfor %} {% endif %}>
{{ item.name }}
</td>

somehow, it's not working for me, even though I'm using everything (data-html etc.) like advised in the answer.

My output looks like that:

Upload Profile ID: 15 <br> Upload Profile Name: Example

Any idea why this could be?

sonja
  • 924
  • 1
  • 21
  • 52

1 Answers1

0
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <table class="table">
            <tbody>
                <tr>
                    <td {% if item.uploadprofiles %} 
                        data-toggle="tooltip" 
                        data-html="true" 
                        title={% for up in item.uploadprofiles %} "Upload Profile ID: {{ up.id }} <br> Upload Profile Name: {{ up.name }}" {%  endfor %} {% endif %}>
                        {{ item.name }}
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        $(document).ready(function () {
            $('[data-toggle="tooltip"]').tooltip();
        });
    </script>
</body>

I tried your code like above and it works fine for me, maybe it is your bootstrap or jquery version, maybe your browser. Your output was shown in a black overlay right? To debug I would start with a simple page.

otherwise maybe you could try :

$('[data-toggle="tooltip"]').tooltip({html:true});

which was also working for me.

Tim Zwinkels
  • 340
  • 4
  • 10
  • thanks Tim, might be, that it's my browser. I tried your code and will wait until the next push from the project to see if it's working on other browsers! – sonja Jan 05 '18 at 15:22