carbon-fields-docs
carbon-fields-docs copied to clipboard
Documentation showing reuse
All documentation examples show single-use case. Would be nice to see a page dedicated to showing how fields/complex fields can be reused. I feel like that's where the real power of this library is. Showing how to do it via functional programming like below as well as a class declaration I'm sure would be helpful to some:
function getLinkGroup($name = 'link') {
return Field::make( 'complex', $name )
->add_fields( array(
Field::make( 'text', 'linktext'),
Field::make( 'text', 'url'),
Field::make( 'checkbox', 'newtab' ) )
)
);
}
function getImageGroup( $name = 'image' ) {
return Field::make( 'complex', 'image' )
->add_fields( array(
Field::make( 'image', 'mobile' ),
Field::make( 'image', 'tablet' ),
Field::make( 'image', 'desktop' ) )
)
}
function getWysiwyg( $name = 'content' ) {
return Field::make( 'rich_text', $name )
}
Container::make( 'post_meta', 'Author Info' )
->where( 'post_type', '=', 'post' )
->add_fields( array(
getLinkGroup(),
getImageGroup( 'avatar' ),
getWysiwyg() )
);
Container::make( 'post_meta', 'Call To Action Button' )
->where( 'post_type', '=', 'page' )
->add_fields( array(
getLinkGroup() )
);
Very useful example, thanks @mindfullsilence . Iv'e send a pull request https://github.com/htmlburger/carbon-fields-docs/pull/30