Problem whith output color picker in gutenberg block builder

Support MB Blocks Problem whith output color picker in gutenberg block builderResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #26939
    IMAGINA LA WEBIMAGINA LA WEB
    Participant

    hi i am in group editor using color picker field.

    the output of the field {{ color_2ik1pu639fe }} using your visual editor (Block Render Settings
    in code option) and the corresponding variable shows me <span style="display:inline-block;width:20px;height:20px;border-radius:50%;background:#8224e3;"></span>

    I just need the color code, but it generates a html with styles that I don't need. How do I get it to generate only the hecadecimal? (I'm going to use it as a css variable).

    #26944
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for getting in touch.

    If you output the field ID like this {{ color_2ik1pu639fe }}, it will include the HTML tag as the helper function rwmb_the_value() does. We recommend using the helper function mb_get_block_field() to get the raw value of a field. Here is the sample code:

    {% set my_color = mb.mb_get_block_field( 'color_2ik1pu639fe' ) %}
    <a href="#123" style="color: {{ my_color }}">The color is</a>

    Get more details here https://docs.metabox.io/extensions/mb-blocks/#block-data.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.