Created
March 18, 2015 12:24
-
-
Save emohamed/1117a1bada3a65809f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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