Giter Site home page Giter Site logo

split filter not working about dotliquid HOT 7 CLOSED

dotliquid avatar dotliquid commented on June 9, 2024
split filter not working

from dotliquid.

Comments (7)

Attosius avatar Attosius commented on June 9, 2024 1

If someone have this bug, try to use CamelCase with operators

{% assign testArray = "first/second/third/fourth" | Split: '/' %}

First element: {{testArray | First}}
Last element: {{testArray | Last}}
Size: {{testArray | Size}}

It helped me

from dotliquid.

microalps avatar microalps commented on June 9, 2024 1

@thinkOfaNumber this is expected behavior

  1. split and Split are not synonyms. Depending on the selected naming convention, one or the other will work. In your case, the CSharpNamingConvention seems in use.
  2. Using an unknown filter is ignored and value remains unchanged. SO: split results in string object while Split has a string array.
  3. string are char array in c# so for loops on the former iterate character by character while the string array works as you want.

from dotliquid.

tgjones avatar tgjones commented on June 9, 2024

Thanks for the heads-up - this filter was added to Liquid fairly recently, and I've ported it to DotLiquid. Fixed by de1c318.

from dotliquid.

rracasanu avatar rracasanu commented on June 9, 2024

Thanks for adding it. However, I don't think this is working properly for all cases. For example, suppose I have a string that I would want to split and then use part of it. It seems that I cannot assign it to an array, as I've tried:

{% capture testArray %}{{ "first/second/third/fourth" | split:"/" }}{% endcapture %}

First element: {{testArray | first}}
Last element: {{testArray | last}}

{% assign testArray1 = "first/second/third/fourth" | split: '/' %}
First element: {{testArray1 | first}}
Last element: {{testArray1 | last}}

The only thing I can do is get the first or last element, like this, but not the other ones:

{% capture firstValue %}{{ "first/second/third/fourth" | split:"/" | first}}{% endcapture %}
{{firstValue}}

{% capture lastValue %}{{ "first/second/third/fourth" | split:"/" | last}}{% endcapture %}
{{lastValue}}

from dotliquid.

tgjones avatar tgjones commented on June 9, 2024

Do you mean you want to access an array element at an arbitrary index? If you could include the code you hope to be able to write, that would help.

Just to be clear, this works fine for me - I'm not sure if you were saying that it's not working:

{% assign testArray1 = "first/second/third/fourth" | split: '/' %} 
First element: {{testArray1 | first}}
Last element: {{testArray1 | last}}

from dotliquid.

Ankasalahari avatar Ankasalahari commented on June 9, 2024

Here is the one of the example
"franchises":[
{% assign beatles = "12,34" | split: "," %}

{% for member in beatles %}
{
number" : {{ member }}
},
{% endfor %}
]
here the split is not working and i'm getting output like
"franchises": [
{
"number": "1"
},
{
"number": "2"
},
{
"number": ","
},
{
"number": "3"
},
{
"number": "4"
}
]

from dotliquid.

thinkOfaNumber avatar thinkOfaNumber commented on June 9, 2024

It's 2023, is this an undocumented feature?

{%- assign emailLowerSplit = "[email protected]" | split: '@' -%}
{%- assign emailUpperSplit = "[email protected]" | Split: '@' -%}
{% for part in emailLowerSplit -%}
  {{ part }}
{% endfor %}
{% for part in emailUpperSplit -%}
  {{ part }}
{% endfor %}

produces

m
e
@
h
e
r
e
.
c
o
m

me
here.com

from dotliquid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.