Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try Building a Template Block #1970

Closed
wants to merge 5 commits into from
Closed

Try Building a Template Block #1970

wants to merge 5 commits into from

Conversation

nb
Copy link
Member

@nb nb commented Jul 21, 2017

A super common use-case I‘ve found for blocks has been to build interactive templates users can insert into their post.

template

Few interesting learnings:

  • It was shorter and more powerful than I though. Generating parts of the text based on others was trivial, see the tagify function.
  • In order to not duplicate markup, we needed a higher-order function – something we need to make sure developers are familiar with as a pattern.
  • It would’ve been a lot easier if I had a “connected” input, which syncs its value with an attribute.
  • Building the transformation to a text block was harder than I thought – it required some level of understanding of how React renders components (and wild be harder if we weren't using functional components).

All in all if we provide some connected inputs and a shortcut to the text transform this could be an incredibly useful way of building a whole class of blocks and maybe a good introduction of both users and developers to Gutenberg.

@nb nb added [Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Status] In Progress Tracking issues with work in progress labels Jul 21, 2017
@nb nb changed the title [Do Not Merge] Try Building a Template Block Try Building a Template Block Jul 21, 2017
@lkraav
Copy link

lkraav commented Jul 21, 2017

@nb could you elaborate on what an "interactive template" is in this context?

EDIT thanks for adding the screencast. Very interesting. I hadn't thought of these workflows yet.

@nb
Copy link
Member Author

nb commented Jul 21, 2017

@lkraav I added a short screencast to show how it works – see how there is a #-tag automatically derived from the name I am adding.

@mtias
Copy link
Member

mtias commented Jul 24, 2017

Very neat. With the combination of placeholder blocks and blocks with "fillable" content, it opens a lot of possibilities for content creation. I agree if we can make this simple—the code is very little, if we don't count transformations ;)—it'd be a great benefit.

nb added 4 commits July 25, 2017 11:28
Currently named `transformComponentToText`, open to other names.

Also may open the door for other transforms like this.
Its value is always in sync with an attribute.
Make it inline, so that we can safely put in a text block later.
`AttributeInput` and `transformComponentToText`
@nb
Copy link
Member Author

nb commented Jul 25, 2017

Added few more commits extracting common template functionality:

  • <AttributeInput type="text" value={ attributes.baba } attribute="baba" setAttributes={ setAttributes } />
  • Easier transforms: transforms: { to: [ transformComponentToText( template( 'save' ) ) ], },. This will make so that transform to core/text uses our save component.

import { getBlockTypes, unregisterBlockType, setUnknownTypeHandler, registerBlockType } from '../registration';
import { Component } from 'element'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a separate "WordPress dependencies block":

https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#imports

Note with #2172, these need to be updated to prefix the dependencies with @wordpress/. You will need to perform a rebase against the latest version of master and apply your changes:

git fetch origin
git rebase origin/master

@youknowriad
Copy link
Contributor

youknowriad commented Jan 29, 2018

Not certain about the status of this PR. Also, the intent seems unclear to me. What can we do to unblock this?

@youknowriad youknowriad added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Jan 29, 2018
@nb
Copy link
Member Author

nb commented Jan 30, 2018

The intent was to experiment with building some templates and see what abstractions/tools might be useful to include in Gutenberg to help developers create more templates.

In the specific case, I think both AttributeInput and the transform function could be useful and the the template pattern could go in the documentation.

@aduth
Copy link
Member

aduth commented Sep 13, 2018

I believe #7352 is related as a since-closed effort to attempt syncing of attributes to input values.

It doesn't appear likely that work here will be resumed, so I'm closing the pull request as stale.

@aduth aduth closed this Sep 13, 2018
@aduth aduth deleted the try/template branch September 13, 2018 18:27
@ceyhun ceyhun mentioned this pull request Apr 27, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Status] In Progress Tracking issues with work in progress [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants