A WordPress plugin that demonstrates how to easily add frontend interactivity with Alpinejs.

Overview

Add Alpinejs to Custom Gutenberg Blocks

Is there a fun/easy/lightweight way to add frontend interactivity to custom Gutenberg blocks w/o using React or jQuery? 🤔

Yes! 👇

@Alpine_JS (16.3kb gzipped)

Spread alpinejs directives into a custom block's save() function:

Alpinejs Example Block on the Frontend.
); ">
save() {
return (
 <div
  { ...useBlockProps.save() }
  { ...{ 'x-data': '{ show: false }' } }
 >
  <div
   className="block"
   { ...{ ':class': `{'block': show, 'hidden': ! show }` } }
  >
   Alpinejs Example Block on the Frontend.
  </div>
  <button
   { ...{ '@click':'show = !show' } }
  >
   <span
    className="hidden"
    { ...{ ':class': `{'hidden': show, 'block': ! show }` } }
   >Show Text</span>
   <span
    className="block"
    { ...{ ':class': `{'block': show, 'hidden': ! show }` } }
   >Hide Text</span>
  </button>
 </div>
);

Try it out

Run the commands below to fire up a server and test it out.

  • requires Docker, Nodejs
git clone https://github.com/blockhandbook/alpine.git

npm install

npm run build

npm run server:start

npm start
You might also like...
A PHP Class for creating Wordpress Custom Post Types easily

N.B I've released an updated version of the project to a new repository, PostTypes. WP Custom Post Type Class v1.4 A single class to help you build mo

This WordPress Plugin Boilerplate is meant for you to develop your own plugin on.

WordPress Plugin Boilerplate This plugin boilerplate is meant for you to develop your own plugin on. Support & collaboration Features OOP plugin core

A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.

WP Bootstrap Navwalker This code in the main repo branch is undergoing a big shakeup to bring it in line with recent standards and to merge and test t

A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.
Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.

Twenty Twenty-Two Welcome to the development repository for the default theme that will launch with WordPress 5.9. About Twenty Twenty-Two is designed

Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer.

Description Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer. Support [audio] tag, compatible with AMP. Requirement WordPr

WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API

Wordpress XML-RPC PHP Client A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API Created by Hieu Le MIT licensed. Cur

Add WooCommerce support and functionality to your WPGraphQL server

WPGraphQL WooCommerce (WooGraphQL) Docs • AxisTaylor • Join Slack Quick Install Install & activate WooCommerce Install & activate WPGraphQL Download t

Owner
null
This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients

theme-setup This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients How to use Just copy c

Abdul Razzaq 1 Nov 27, 2021
WPCloudDeploy is a WordPress plugin that allows you to easily deploy servers at major cloud-server providers and then install apps

WPCloudDeploy is a WordPress plugin that allows you to easily deploy servers at major cloud-server providers and then install apps

WPCloudDeploy 41 Dec 24, 2022
Ormapker is a wordpress plugin to embbed a multilocations map easily.

ORMAPKER Ormapker is a wordpress plugin to embbed a multilocations map easily. License This plugin is released under the GNU General Public License Ve

Said Gamih 1 Aug 10, 2022
Add time dismissible admin notices to WordPress

WP Dismiss Notice Add time dismissible admin notices to WordPress. Fork of https://github.com/w3guy/persist-admin-notices-dismissal Instuctions Initia

Andy Fragen 6 Aug 24, 2022
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Contact us for any customization: contact@binsh

Binshops 279 Dec 28, 2022
A simple little WordPress block that allows you add social share icons to your website.

Social Sharing Block This plugin requires WordPress 5.9+ or 5.8+ with Gutenberg active. A simple little block that allows you to add social share icon

Nick Diego 18 Dec 27, 2022
The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Pronamic 1 Oct 19, 2021
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022