Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel: text-overflow:ellipsis does not work with displaying unescaped data

I’m having a problem with the property text-overflow:ellipsis.

In particular, the three points at the end of the broken line are not displayed.

Since I don’t want to escape the data, since I use ckeditor (hence formatted text), I use the following wording

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{!! $treatment->description !!}

for the Description column only.

This is my code:

<table id="tabledata" class="table table-striped hover" style="width:100%">
            <thead>
                <tr>
                    <th></th>
                    <th>Title</th>
                    <th>Description</th>
                    <th>Stay</th>
                    <th>Price</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($treatments as $treatment)
                <tr>
                    <td></td>
                    <td class="p-4">{{ $treatment->title }}</td>
                    <td class="p-4"><span class="descresize">{!! $treatment->description !!}</span></td>
                    <td class="p-4">{{ $treatment->duration }} </td>
                    <td class="p-4">{{ $treatment->price }} €</td>
                    <td>
                        <a class="btn btn-primary" href="{{route('treatment.edit', compact('treatment'))}}" role="button">Update</a>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>

CSS

.descresize{
    display: inline-block;
    width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;    
}

Can you kindly help me? I am going crazy to solve this problem

>Solution :

In Laravel’s Blade Templating engine, {!! !!} is used to output unescaped content, including (and not limited to) HTML tags. When combined with CKEditor, you typically get things like this:

<span class="descresize">{!! $treatment->description !!}</span>
<!-- <span class="descresize"><p>Something something long description of the associated Treatment</p></span> -->

Since the CSS properties are being assigned to <span class="descresize">, which now equates to <span class="descresize"><p>...</p></span>, the properties may or may not propagate to these nested HTML elements.

If the content of {!! $treatment->description !!} is going to be consistent (i.e. always a <p>...</p> element), you can simply modify the CSS to point at this nested element:

.descresize > p {
  display: inline-block;
  width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;    
}

Since the <p> tag only contains text, and no nested elements, this should handle the properties correctly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading