Skip to content

Instantly share code, notes, and snippets.

@PaulEibensteiner
Created June 15, 2018 14:58
Show Gist options
  • Save PaulEibensteiner/f6d6d907563c9ffcb60c37f6ff79c98f to your computer and use it in GitHub Desktop.
Save PaulEibensteiner/f6d6d907563c9ffcb60c37f6ff79c98f to your computer and use it in GitHub Desktop.
Gallery Custom Editor Component (not working at all)
<script>
CMS.registerEditorComponent({
// Internal id of the component
id: "Gallery",
// Visible label
label: "Añadir Galleria",
// Fields the user need to fill out when adding an instance of the component
fields: [{
name: 'images',
label: 'Images',
widget: 'list',
required: 'false',
fields: [
{label: 'choose image', name: 'image', widget: 'image'},
{label: 'name image', name: 'name', widget: 'string'}
]}],
// Pattern to identify a block as being an instance of this component
pattern: /{{< gallery >}}({{< img name="(.+)" descript="(.+)" >}}){{< \/gallery >}},
// Function to extract data elements from the regexp match
fromBlock: function(match) {
return {
image: match[1],
name: match[2]
};
},
// Function to create a text block from an instance of this component
toBlock: function(obj) {
return '{{< gallery >}}' + '{{< img source="' + obj.image + '" caption="' + obj.name + '" >}}' + '{{< /gallery >}}'
},
// Preview output for this component. Can either be a string or a React component
// (component gives better render performance)
toPreview: function(obj) {
return (
'<img src="' + obj.image + '" alt="' obj.name '" style="width: 33%;">'
);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment