Skip to content

Instantly share code, notes, and snippets.

@bencroker
bencroker / history.ts
Last active October 30, 2024 19:27
History plugin for Datastar – sets store values in `data-history` to the URL param values.
import { AttributeContext, AttributePlugin } from '../types'
export const HistoryPlugin: AttributePlugin = {
prefix: 'history',
mustHaveEmptyKey: true,
mustNotEmptyExpression: true,
onLoad: (ctx: AttributeContext) => {
const { el, expressionFn, store } = ctx
const storeNames: string[] = expressionFn(ctx)
@bencroker
bencroker / demo.twig
Last active October 19, 2024 19:39
Spark Demo – Inline Table Editing
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Spark Demo</title>
<meta charset="utf-8"/>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css" rel="stylesheet" type="text/css"/>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
{# https://tailwindcss.com/docs/container #}
@bencroker
bencroker / sample-pest-tests.php
Last active May 16, 2023 23:56
Sample Craft Pest tests.
<?php
/**
* Sample Craft Pest tests.
*
* @copyright Copyright (c) PutYourLightsOn
*/
use markhuot\craftpest\factories\Entry;
use markhuot\craftpest\factories\User;
@bencroker
bencroker / README.md
Last active February 28, 2022 10:25
Craft 4 Plugin Changes

Craft 4 Plugin Changes

Composer Requirements

Before

"require": {
   "craftcms/cms": "^3.0.0"
},

After

<?php
namespace modules;
use Craft;
use craft\controllers\EntriesController;
use craft\controllers\UsersController;
use yii\base\ActionEvent;
use yii\base\Event;
use yii\base\Module;
use yii\web\ForbiddenHttpException;
@bencroker
bencroker / _productComponent.twig
Last active November 3, 2020 22:35 — forked from piotrpog/product.twig
Commerce product page with Sprig
{% set variantParam = 'variant' %}
{# set product #}
{% set product = craft.products.id(productId).one() %}
{# set variant #}
{% set variant = product.defaultVariant %}
{# overvrite default variant with url param #}
{% if product.variants|filter(v => v.id == craft.app.request.getParam(variantParam)) is not empty %}