Giter VIP home page Giter VIP logo

Comments (4)

mhw avatar mhw commented on August 20, 2024 1

Hmm; it doesn't look like it, at least not using that kind of syntax and approach. As you say, capture always assigns a string to the variable, so that won't work, and the if tag doesn't support filters so the original syntax you suggest won't work either.

A kludge that might work would be to define a filter called something like gt that worked along the lines of the existing plus and minus filters, then you should be able to do something like:

{% capture too_long %}{{ page.content | number_of_words | gt: 200 }}{% endcapture %}
{% if  too_long == "true" %}
   ...
{% endif %}

Slightly less of a kludge might be to add a content_word_count method to the page drop, if you can.

Another option is the following hack:

{% capture truncated %}{{ page.content | truncatewords: 200, '' }}{% endcapture %}
{% if truncated != page.content %}
   ...
{% endif %}

I agree, though, that it would be useful if the syntax was a bit more flexible and didn't require these hacks.

from liquid.

mhw avatar mhw commented on August 20, 2024

Can you use the capture tag to put the output of the filter chain into a variable? Something like this:

{% capture word_count %}{{ page.content | number_of_words }}{% endcapture %}
{% if word_count > 200 %}
   ...
{% endif %}

from liquid.

drekka avatar drekka commented on August 20, 2024

I tried that, but it saved the rsult as a string so the if statement could not do the comparison. Is there something I can do to get liquid to see a string as a number?

from liquid.

drekka avatar drekka commented on August 20, 2024

Thanks, I'll give those a try. I agree that they are "kludgy". I cannot modify or define anything because this is all being uploaded to github and they control jekyll, not me. :-(

I don't know if it's practical or not, but having tags be able to run embedded filters or at least have capture set a type appropriate to the return value would be really useful.

from liquid.

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.