Giter Club home page Giter Club logo

liquid.js's Introduction

Liquid.js

Liquid.js is a browser version of the Liquid Templating language (see http://github.com/shopify/liquid).
Liquid.js is available as both plain JavaScript and as minified JavaScript.

In addition to core Liquid, Partials from my node-liquid-partial project have been added as a way to reduce duplication in markup. You register templates and reference them via the {% partial %} tag.

This library is built in the node-liquify project. See that project for details on what other projects are used to build Liquid.js.

Usage

You may simply reference the liquid.js/liquid.min.js file in your page, register your partials (if you use them), and enjoy!

<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Client-Side Liquid Templates</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

	<script type="text/javascript" src="./javascripts/liquid.min.js"></script>
    <script type="text/javascript">
      var Liquid = require('liquid');
    </script>
  </head>

  <body>
    <script id="simplewithfilter" type="text/liquid">
      <div>Here is the value of foobar in uppercase: <strong>{{ foobar | upcase }}</strong></div>
    </script>

	<script id="ifblock" type="text/liquid">
      <div>
        Trying out the if block.  If it works, you should see "Hooray!":&nbsp;
        {% if cheer %}
        Hooray!
        {% else %}
        Boo!
        {% endif %}
      </div>
	</script>

	<div id="page" style="display:none;">
      {% partial simplewithfilter %}
      {% partial ifblock %}
	</div>

    <script type="text/javascript">
      $(function() {
        Liquid.Partial.registerTemplates();  // Finds all script tags with type="text/liquid" and registers them as partials

        var page = $('#page');
        var pageTemplate = page.html();
        page.html(Liquid.Template.parse(pageTemplate).render({ foobar: 'bizbuzz', cheer: true })).show();
      });
    </script>
  </body>
</html>

Results in the following html page:

Here is the value of foobar in uppercase: BIZBUZZ

Trying out the if block. If it works, you should see "Hooray!": Hooray!

Acknowledgements

I have to take a minute to recognize the efforts of others.

The huge, gigantic THANK YOU has to go to sirlantis (Marcel Jekwerth) for even taking on the task of porting Liquid into node. Without his work on this front, I probably would have given up trying to implement it in purely client-side JavaScript at some point. Instead, his previous efforts and eagerness to accept pull requests and ideas for liquid-node have made it simply less than a week-long project to get something working!

Also, a big thank you goes out to substack for browserify as well as the overall contributions to node and Open Source. Thanks!

Finally, the biggest thank you (as well as an "I'm sorry for keeping my nose in the computer all weekend") has to go to my lovely wife and my silly, wonderful boys. Thanks for being patient with me!!

liquid.js's People

Contributors

heupel avatar

Stargazers

Anne Thorpe avatar  avatar  avatar Ioannis Mentesidis avatar Thiguet avatar 项小健 avatar Jack Pritchard avatar Danny Page avatar  avatar LIU Hui avatar Spencer avatar Bohdan Yurov avatar Adam Yarger avatar Benjamin Geck avatar  avatar Adam Wooding avatar Jan Martinek avatar Batuhan Göksu avatar Ryan Mark avatar Victor Kuznetsov avatar Luiggi Anguiano avatar LM avatar Si Nguyen avatar Mike Bohman avatar Jeremiah Currier avatar James Kassemi avatar  avatar  avatar Ben Johnston avatar Mario avatar Lau Borges avatar James Andrew-Smith avatar Jeff Turcotte avatar Christanto Leonardo avatar Dean Neitman avatar Volkan Özçelik avatar Krister Kari avatar Matt Hayes avatar Howard Nguyen avatar Xavier Cambar avatar Neville Franks avatar Ivan Kotelnikov avatar Ken D: Uemura avatar Dan Levy avatar Tony C. Heupel avatar Andi Idogawa avatar  avatar Anders Haig avatar Zdenko Nevrala avatar Trung Lê avatar Ryan Blunden avatar Rob Sutherland avatar Haifeng Cao avatar Tomasz Bak avatar Thomas Heinrichsdobler avatar  avatar David Chien avatar Aleksey Ostapenko avatar  avatar Josh Nesbitt avatar Chetan Sarva avatar Anthony Petruzzi avatar 7rans avatar Chris Mytton avatar Rupak Ganguly avatar Nathan Youngman avatar Corey Reece avatar Bjørn Mæland avatar  avatar

Watchers

Krister Kari avatar Venkatta avatar  avatar

liquid.js's Issues

Bug with case when structure

Hi,
I've looked for a couple of hours for a problem on my side, before finally being quite sure it's a bug.
After many tests I got on following simplified bug-reproducing-case:

{% assign v = '2' %}
{% assign t1 = 'one' %}
{% assign t2 = 'two' %}
{% assign t3 = 'more' %}

<br>if structure:
{% if v == '1'%}{{t1}}
{% elsif v == '2'%}{{t2}}
{% else %}{{t3}}
{% endif %}

<br>case structure:
{%case v %}
{% when '1' %}{{t1}}
{% when '2' %}{{t2}}
{% else %}{{t3}}
{% endcase %}

The output of this is:

if structure: two
case structure: ,two,

Where there's no reason for the commas before and after the output "two" text in the case syntax.
Thank in advanced for your help if I'm doing smthg wrong... or for a fix ;-)

For loops do not render correctly

Hello writer of an awesome tool,

for loops does not seem to work:

{% for i in (1..4) %}
  {{ i }}
{% endfor %}

it makes the parser fail and returns a blank page.

Any ideas on how I can help to debug this? (is there a flag to throw errors?)

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.