Question

Photo of Michael Garrison

0

Liquid/Lava help: split

I'm trying to create a profile block which shows the results of a key-value pair using a Dynamic Content block type.

The data appears to be stored in the following format:

key1^value1|key2^value2|

So it should be pretty easy to split the string first on the pipes (|) and then on the carets (^). Here's the code I came up with just to ensure I could split on the pipes (within that loop I was then going to split on the carets and display):

{% for row in rows %}
    {% assign lines = {{row.Value}} | split: '|' %}
{% endfor %}
{% for line in lines %}
    {{line}}<br />
{% endfor %}

But what it outputs is one character per line! And that's no matter what parameter I put in: a number, a space, whatever.

Can someone with more experience with Liquid spot my mistake?

Thanks!

  • Photo of Rock RMS

    0

    Rock's Lava implementation is an extension of DotLiquid and uses the C# notation. So.. you just need to change the case of your 'Split' filter to start with an upper-case 'S'.

    Here's an example Lava template you could use to display a KeyValue attribute's individual key values formatted like the AttributeValues block:

    {% assign rawValue = Context.Person | Attribute:'BenevelenceAmounts','RawValue' %}
    {% assign splitValues = rawValue | Split: '|' %}
    
    <section class="panel panel-persondetails">
    	<div class="panel-heading rollover-container clearfix">
    		<h3 class="panel-title pull-left">
    			<i class="fa fa-gift"></i> Benevolence Details
    		</h3>
    	</div>
    	<div class="panel-body">
    		<fieldset class="attribute-values">
    			{% for pairValues in splitValues %}
    				{% assign values = pairValues | Split:'^' %}
    				<div class="form-group static-control">
    					<label class="control-label">{{ values | First }}</label><p class="form-control-static ">{{ values | Last }}</p>
    				</div>
    			{% endfor %}
    		</fieldset>
    	</div>
    </section>