carbon-fields-docs icon indicating copy to clipboard operation
carbon-fields-docs copied to clipboard

Documentation showing reuse

Open mindfullsilence opened this issue 6 years ago • 1 comments

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() )
        );

mindfullsilence avatar Jul 10 '17 20:07 mindfullsilence

Very useful example, thanks @mindfullsilence . Iv'e send a pull request https://github.com/htmlburger/carbon-fields-docs/pull/30

BenBroide avatar Dec 28 '17 15:12 BenBroide