• Resolved David Levine

    (@justlevine)


    I am trying to create a custom block that will let users use merge tags in the content.
    E.g Today is {my_block_date:y-m-d} => Today is 2022-3-16.
    (Ignore the specific example, some use cases are dynamic but most aren’t).

    I need to:
    – show a replacement value on the preview/frontend.
    – show a replacement value in the block editor
    – indicate in the block editor where the merge tag is used. Either by decorating the replacement value or showing the {merge_tag} when the block content is being edited.
    – (bonus) submit the block to the block directory.

    Any idea how this can be do this?

    ## What I’ve tried:
    – replacing the {merge_tage} in php with add_filter('render_block',...). You cant see the values in the editor, and my understanding of the block directory guidelines is to keep php empty except for the register_block_type() call.
    – replacing the {merge_tag} in edit.js with setAttributes( {content: replaceMergeTags( newContent )} ). This is destructive, replacing the tag on the front and backend with no indicator it was ever used.
    – replacing the {merge_tag} in edit.js with <RichText ... value={replaceMergeTags( newContent )} />. This keeps the original tag in the attribute, and shows the replacement in the editor, but you still need to use add_filter('render_block',...) for the frontend, and no indicator of the tag was used in the editor.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Replacing {merge_tag} in block’ is closed to new replies.