Giter Club home page Giter Club logo

alpinejs-tash's Introduction

Alpine JS Tash

Alpine JS plugin to stop the need of x-text="..." to render Alpine JS data ๐Ÿฅณ

Example ๐Ÿ‘€

Core

Here's the approach you'd take if you were using x-text

<div x-data="{ name: 'Mark', age: 24, company: 'Neon & GetCandy' }">
  <p>
    Hello I am <span x-text="name"></span> and I am
    <span x-text="age"></span> years old, currently I work at
    <span x-text="company"></span>
  </p>
</div>

Plugin

Here's the approach you'd take if you were using x-tash

<div x-data="{ name: 'Mark', age: 25, company: 'Neon & GetCandy' }">
  <p x-tash="name,age,company">
    Hello I am {name} and I am {age} years old, currently I work at {company}
  </p>
</div>

You can add spaces after your commas in x-tash, it doesn't have to follow the example format

๐Ÿ™‹ You don't have to render every variable

From the example, if you wanted to render the name and age then you can pass x-tash="name,age and {company} will be ignored! ๐Ÿคฉ

Install ๐ŸŒŸ

It's very easy to install Alpine JS plugins! ๐Ÿ™Œ

CDN

<script
  defer
  src="https://unpkg.com/[email protected]/dist/tash.min.js"
></script>

<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

NPM/Yarn

npm i -D alpinejs-tash

yarn add -D alpinejs-tash

Then you can register the plugin.

import Alpine from 'alpinejs'
import tash from 'alpinejs-tash'

Alpine.plugin(tash)

window.Alpine = Alpine

Alpine.start()

Options ๐Ÿง

Changing Delimiters

It's possible to change the defaul delimiters {} by adding the x-tash-delimitiers attribute.

<p x-tash="..." x-tash-delimiters='["{{", "}}"]'>...</p>
<p x-tash="..." x-tash-delimiters='["*", "*"]'>...</p>
<p x-tash="..." x-tash-delimiters='["@@", "@@"]'>...</p>
<p x-tash="..." x-tash-delimiters='[":", "("]'>...</p>

It's required to wrap the value of x-tash-delimiters in single quotes.

Stats ๐Ÿ“Š

alpinejs-tash's People

Contributors

markmead avatar

Stargazers

 avatar

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.