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

Allow overriding the templateLock of existing blocks #9386

Closed
haszari opened this issue Aug 28, 2018 · 5 comments
Closed

Allow overriding the templateLock of existing blocks #9386

haszari opened this issue Aug 28, 2018 · 5 comments
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement.

Comments

@haszari
Copy link
Contributor

haszari commented Aug 28, 2018

Is your feature request related to a problem? Please describe.
We're using templates to implement reusable chunks of layout for landing pages. For example, a call-to-action header block with two columns containing heading, text, an image, a button, and some custom styling.

Templates are really powerful and convenient for this purpose, but there are quirks that are causing problems for us:

  • It's hard to navigate nested blocks. In particular, it's very easy to add new blocks inside another block's outer container (and it's conversely hard to add things to the top-level page).
  • When containers allow editing, a placeholder core/paragraph block is added, which is not needed for our layouts, and causes issues on the front end.

To work around these issues, we're looking at locking all our template blocks for now using templateLock. This will reduce the flexibility of the blocks, but will make things much simpler and more predictable for our authors.

This works well most of the time. However, when a template contains columns, the columns block overrides templateLock locally. This is frustrating, because the extra placeholder paragraph appears again, breaking the layout, and allowing accidental insertion of a template within a template!

Describe the solution you'd like
Since we are instantiating the columns blocks (and their children) directly within our template, it seems appropriate that we could instruct them to not allow editing. If core/columns had a forceLock attribute, which inhibited the override, we could set this as needed in our templates.

Describe alternatives you've considered
Would love to hear other ideas for how to work around this. Here are some ideas:

  • Implement our own custom columns block, and not use core/columns block.
  • Implement our columns as markup directly in our template blocks, and use multiple template/InnerBlocks. (Is this possible?)
@haszari
Copy link
Contributor Author

haszari commented Aug 28, 2018

This issue More versatile templateLock could potentially help with this, though the scope there is much broader.

@designsimply designsimply added [Type] Enhancement A suggestion for improvement. [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Aug 28, 2018
@designsimply
Copy link
Member

Would #8589 work as a solution to problems you described where empty placeholder blocks are causing layout issues in this case?

@designsimply designsimply added the Needs Technical Feedback Needs testing from a developer perspective. label Aug 28, 2018
@haszari
Copy link
Contributor Author

haszari commented Sep 5, 2018

@designsimply I'm not sure! When #8589 converges on a solution we can see how it works for us.

@youknowriad youknowriad changed the title Allow templates to control whether child blocks allow editing Allow overriding the templateLock of existing blocks Jan 30, 2019
@youknowriad
Copy link
Contributor

I think it should be explored whether we could override the "templateLock" of existing container blocks, the same we're able to do it for the "template" content.

@youknowriad youknowriad added [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later and removed Needs Technical Feedback Needs testing from a developer perspective. labels Jan 30, 2019
@t-hamano
Copy link
Contributor

At least for Columns/Column blocks, templateLock is added as an attribute and should inherit the parent's templateLock setting.

In the markup below, Columns/Column blocks exist within a group block that has templateLock:true set.

<!-- wp:group {"templateLock": "all","layout":{"type":"constrained"}} -->
<div class="wp-block-group">
  <!-- wp:columns -->
  <div class="wp-block-columns">
    <!-- wp:column -->
    <div class="wp-block-column"></div>
    <!-- /wp:column -->
    <!-- wp:column -->
    <div class="wp-block-column"></div>
    <!-- /wp:column -->
  </div>
  <!-- /wp:columns -->
</div>
<!-- /wp:group -->

template-lock

You can see that the Columns/Column blocks inherit the Group block's templateLock and are locked. Furthermore, you can also roverride this lock for specific columns only.

As far as I know, there is no container block that supports templateLock that does not respect the parent's templateLock setting.

Therefore, I would like to close this issue, but if there is anything I have missed, please comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants