Text Columns

Problem

You want to create multiple columns from a text string

Solution

{# Get the string from Craft #}
{% set str = entry.str %}

{# Split the string into an array of words #}
{% set strArray = str|split(' ') %}

{# Get the length of the array and divide by the amount of columns you want #}
{% set strArrayLength = strArray|length / 2 %}

<div class="row">
{# Splits the array into batches of the length you set above #}
{# For each batch: #}
{% for column in strArray|batch(strArrayLength) %}
    <div class="col-md-6">
         {# For each word in batch: #}
          <p>{% for word in column %}{{ word }} {% endfor %}</p>
    </div>
{% endfor %}
</div>