Skip to content

Instantly share code, notes, and snippets.

@emohamed
Created March 18, 2015 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emohamed/1117a1bada3a65809f50 to your computer and use it in GitHub Desktop.
Save emohamed/1117a1bada3a65809f50 to your computer and use it in GitHub Desktop.
Carbon Fields use Underscore template engine. Each field has a `template` method that prints the underscore template code.
```
class Carbon_Field_Example extends Carbon_Field {
// Base template
function template() {
?>
<input id="{{{ id }}}" type="text" name="{{{ name }}}" value="{{ value }}" class="regular-text example-field" />
<span>This is an example field. </span>
<?php
}
}
```
Some fields have more than one template - in those cases the extra templates should be printed in separate methods and registered via `add_template($name, $callback)` method.
```
class Carbon_Field_File extends Carbon_Field {
function init() {
// Add the file description template to the templates stack
$this->add_template($this->get_type() . '-Description', 'template_description');
}
...
// File description template
function template_description() {
?>
<div class="carbon-description {{{ value ? '' : 'hidden' }}}">
<a href="{{ value }}" target="_blank" class="carbon-view_file">View File</a>
</div>
<?php
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment