Reputation: 845
What i Need:
how to calculate the length of four companies, and restrict on length so that only four companies are view on dashboard.
Our Mid Level Transport System ,
Intelligent Ethernet Access System (Ieas 05) ,
In-Line Amplification Systems
Intelligent Ethernet Access System (Ieas 03) .
i want that consider there are four companies name if 5 is added then it woudn"t reflect.
Here is what i have tried.
{% set foo = item.Product_Name|split(',') %}
{% for i in foo|slice(0, 5) %}
{{ i|length > 50 ? i|slice(0, 100) ~ ' ' : i }}
{% if(loop.last)< 5 %}
,
{% endif %}
{% endfor %}
Upvotes: 1
Views: 5105
Reputation: 17759
How about...
{% set names = item.Product_Name|split(',') %}
{% set maxNames = 4 %}
<ul>
{% for name in names|slice(0, maxNames) %}
<li>
{{ name|length < 50 ? name : name|slice(0, 50) ~ '...' }}
</li>
{% else %}
<li>No Results</li>
{% endfor %}
{% if names|length > maxNames %}
<li>More Results Available</li>
{% endif %}
</ul>
If not then I'm clearly not too sure about what you are actually after.
Also, what is the need for the ,
's in between each name?
If you are wanting something more complex then there is the possibility it should be handled outside of the template and in some kind of twig function.
Upvotes: 4