All Projects → aquibm → react-liquid

aquibm / react-liquid

Licence: MIT license
Liquid templating language component for React

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-liquid

dry
Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.
Stars: ✭ 66 (+32%)
Mutual labels:  liquid, liquid-templating-engine
liquidpy
A port of liquid template engine for python
Stars: ✭ 49 (-2%)
Mutual labels:  liquid, liquid-templating-engine
liquid
A Python engine for the Liquid template language.
Stars: ✭ 40 (-20%)
Mutual labels:  liquid, liquid-templating-engine
gulp-shopify-theme
Shopify theme synchronisation during development
Stars: ✭ 26 (-48%)
Mutual labels:  liquid, liquid-templating-engine
mechanic-tasks
Public task repository for Mechanic (https://mechanic.dev)
Stars: ✭ 42 (-16%)
Mutual labels:  liquid, liquid-templating-engine
agency-jekyll-theme
Jekyll version of the newest Agency Bootstrap theme, plus new features: Google Analytics, Markdown support, custom pages, and more!
Stars: ✭ 222 (+344%)
Mutual labels:  liquid
liquid button
Liquify your buttons, web demo at website
Stars: ✭ 18 (-64%)
Mutual labels:  liquid
biketag-website
A website for biketag.org
Stars: ✭ 34 (-32%)
Mutual labels:  liquid
vscode-liquid
💧Liquid language support for VS Code
Stars: ✭ 137 (+174%)
Mutual labels:  liquid
scalem
A jQuery plugin to make any element scalable (responsive).
Stars: ✭ 33 (-34%)
Mutual labels:  liquid
Liquid
An advance flutter UI Kit for developing responsive, cross platform applications.
Stars: ✭ 27 (-46%)
Mutual labels:  liquid
Supply
🛍 Supply is a free e-commerce Jekyll theme with Gumroad integration.
Stars: ✭ 24 (-52%)
Mutual labels:  liquid
shopify-wishlist
💙 A set of files used to implement a simple customer wishlist on a Shopify store
Stars: ✭ 115 (+130%)
Mutual labels:  liquid
jekyll-rss-feeds
Templates for rendering RSS feeds for your Jekyll blog
Stars: ✭ 639 (+1178%)
Mutual labels:  liquid
zhangkn.github.io
新博客地址:https://kunnan.blog.csdn.net
Stars: ✭ 20 (-60%)
Mutual labels:  liquid
bitcoin-stack
Docker setup for Bitcoin, Elements/Liquid, LND, C-Lightning, Eclair, & Electrs in regtest mode
Stars: ✭ 66 (+32%)
Mutual labels:  liquid
bootstrap-shopify-theme
🛍 A free Shopify Theme built with Bootstrap, BEM, Liquid, Sass, ESNext, Theme Tools, ... and Webpack.
Stars: ✭ 41 (-18%)
Mutual labels:  liquid
liquid.cr
Kind of liquid template engine for Crystal [WIP]
Stars: ✭ 64 (+28%)
Mutual labels:  liquid
kunnan.github.io
@zhangkn
Stars: ✭ 13 (-74%)
Mutual labels:  liquid
Nescience-Indexing-CLI
Nescience Software & Capital Rebalancing Tool
Stars: ✭ 26 (-48%)
Mutual labels:  liquid

react-liquid

Liquid templating language component for React

NPM

Install

npm install --save react-liquid

or

yarn add react-liquid

Basic Usage

The component will automatically update when template or data are updated via state or props.

import React, { Component } from 'react'

import { ReactLiquid } from 'react-liquid'

class Example extends Component {
    render() {
        const template = 'Hello, {{ name }}'
        const data = {
            name: 'aquibm',
        }

        return <ReactLiquid template={template} data={data} />
    }
}

Extending the Liquid Engine

You can add your own filters and tags to the liquid engine, more information here.

import React, { Component } from 'react'

import { ReactLiquid, liquidEngine } from 'react-liquid'

class Example extends Component {
    constructor(props) {
        super(props)

        liquidEngine.registerFilter('add', (initial, arg1, arg2) => {
            return initial + arg1 + arg2
        })
    }

    render() {
        return <ReactLiquid template="{{ 1 | add: 2, 3 }}" />
    }
}

Rendering HTML

HTML can be dangerously injected by supplying the html prop

import React, { Component } from 'react'

import { ReactLiquid } from 'react-liquid'

class Example extends Component {
    render() {
        const template = '<p style="color: tomato;">{{ name }}</p>'
        const data = {
            name: 'aquibm',
        }

        return <ReactLiquid template={template} data={data} html />
    }
}

Custom rendering via render prop

You can render however you'd like by passing through a render prop

import React, { Component } from 'react'
import { ReactLiquid } from 'react-liquid'

class Example extends Component {
    render() {
        const template = '<p style="color: tomato;">{{ name }}</p>'
        const data = {
            name: 'aquibm',
        }

        return (
            <ReactLiquid
                template={template}
                data={data}
                render={(renderedTemplate) => {
                    console.log('Woohoo! New Render!')
                    return <span dangerouslySetInnerHTML={renderedTemplate} />
                }}
            />
        )
    }
}

useLiquid hook

From version 2.x onwards, you can render markdown using the useLiquid hook.

At the moment, we use JSON.stringify( data ) between render cycles to determine whether we need to re-render the markdown. This is inherently slow and should only be used when data is small and not overly nested. Read more here

import React from 'react'
import { useLiquid, RENDER_STATUS } from 'react-liquid'

const MyAwesomeComponent = ({ template, data }) => {
    const { status, markup } = useLiquid(template, data)

    return (
        <div>
            {status === RENDER_STATUS.rendering && <div>Rendering...</div>}
            <div dangerouslySetInnerHTML={{ __html: markup }} />
        </div>
    )
}

License

MIT © Aquib Master

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].