Skip to content

Instantly share code, notes, and snippets.

@kevinweber
kevinweber / encodeSvg.js
Created October 31, 2016 05:36
Helper: Convert React component (SVG element) to base64 encoded URL. Useful for adding a background image.
import ReactDOMServer from 'react-dom/server';
export function encodeSvg(reactElement) {
return 'data:image/svg+xml,' + escape(ReactDOMServer.renderToStaticMarkup((reactElement)));
}
@kevinweber
kevinweber / Sightly Pattern "Inline List"
Last active February 1, 2024 18:09
AEM/HTL: Define a list/array within a HTL template (and avoid redundant code!)
<!--/* We can define a list within a Sightly template to avoid redundant code */-->
<sly data-sly-test.versions="${['desktop', 'mobile']}"/>
<sly data-sly-list.identifier="${versions}">
<div class="element ${identifier}">Repeated content</div>
</sly>
<alignment jcr:primaryType="nt:unstructured"
name="./alignChildren"
fieldLabel="Alignment of components"
required="{Boolean}true"
selectionMode="single"
sling:resourceType="granite/ui/components/coral/foundation/form/buttongroup">
<items jcr:primaryType="nt:unstructured">
<default jcr:primaryType="nt:unstructured"
name="./default"
@kevinweber
kevinweber / example.html
Last active May 5, 2023 12:22
AEM: Include another resource + modify tag and class name #data-sly-resource
<!--/* More: https://docs.adobe.com/docs/en/htl/docs/block-statements.html#resource */-->
<!--/* By default, the AEM decoration tags are disabled, the decorationTagName option allows to bring them back, and the cssClassName to add classes to that element. */-->
<div data-sly-resource="${'headline' @
resourceType='about-project/components/content/c34-section-headline',
decorationTagName='span',
cssClassName='className'
}"></div>
<!--/* More about the decoration tag: https://docs.adobe.com/docs/en/aem/6-3/develop/components/decoration-tag.html */-->
@kevinweber
kevinweber / _cq_dialog.xml
Last active February 21, 2023 14:44
AEM: Sling Resource Merging & Includes (dialog, inheriting properties)
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured">
<content jcr:primaryType="nt:unstructured">
<items jcr:primaryType="nt:unstructured">
<basic jcr:primaryType="nt:unstructured">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured">
@kevinweber
kevinweber / component.html
Last active September 7, 2022 13:07
HTL/Sightly: "Use and call template" pattern. Put template into separate file for reusability, and pass parameters when calling it. Note that in most cases it's not necessary to pass "properties" to the template because they work even if they're not passed explicitly.
<sly data-sly-use.component="template.html"
data-sly-call="${component.template @ properties=properties}" />
@kevinweber
kevinweber / .content.xml
Last active August 24, 2022 02:01
AEM: Add JavaScript (including events) to AEM loaded on editor.html. Solution: Create clientlib with category "cq.authoring.dialog". Exemplary usage: Reload page if layer changes.
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[cq.authoring.dialog]"/>
@kevinweber
kevinweber / poll.js
Last active July 23, 2022 16:45
Poll function
/**
* Poll function
* based on https://davidwalsh.name/essential-javascript-functions
*/
function poll(fn, callback, errback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
@kevinweber
kevinweber / built-in-tools.md
Last active April 26, 2022 13:50
Collection of AEM Links, Commands & Tips / Cheat Sheet

Web Consoles & Tools

@kevinweber
kevinweber / img
Last active May 7, 2021 07:47
1:1 (and other) ratio placeholder image / pixel / svg. Generate custom sizes via http://png-pixel.com/
<!--/* This is a 1x1 sized PNG */-->
<img class="ratio" alt="" aria-hidden="true" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">
<!--/* This is a 2x1 sized PNG */-->
<img class="ratio" alt="" aria-hidden="true" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAAC0lEQVR42mNkAAIAAAoAAv/lxKUAAAAASUVORK5CYII=">
<!--/* This is a 3x1 sized PNG */-->
<img class="ratio" alt="" aria-hidden="true" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAABCAQAAACx6dw/AAAAC0lEQVR42mNkAAMAAA4AAjOwv9wAAAAASUVORK5CYII=">
<!--/* This is a 4x3 sized PNG */-->