Skip to content

Instantly share code, notes, and snippets.

@sashabeep
Created November 30, 2020 11:19
Show Gist options
  • Save sashabeep/eab25b49990ed09c58e6f3087a4a0ddf to your computer and use it in GitHub Desktop.
Save sashabeep/eab25b49990ed09c58e6f3087a4a0ddf to your computer and use it in GitHub Desktop.
Pagebuilder field type color
<div class="field type-<?= $field['type'] ?>" data-field="<?= $name ?>">
<?php if (!empty($field['caption'])): ?>
<div class="field-name"><?= $field['caption'] ?></div>
<?php endif; ?>
<input type="text" <?php if($value){ echo('style="background-color:'.$value.'"'); } ?> name="contentblocks_<?= $name ?>" value="<?= htmlentities($value) ?>" oninput="this.setAttribute('value', this.value)" onfocus="this.setAttribute('type', 'color')" onblur="this.setAttribute('type', 'text'); this.style.backgroundColor=this.value">
<?php if (!empty($field['note'])): ?>
<div class="field-note"><?= $field['note'] ?></div>
<?php endif; ?>
</div>
@sashabeep
Copy link
Author

sashabeep commented Nov 30, 2020

Place .tpl in assets/plugins/pagebuilder/tpl
Use in pagebuilder config like any text field

'hex' => [
                'caption' => 'Цвет',
                'type'    => 'color',
            ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment