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

Edit Site: Loading a specific context on a dynamic template #19257

Closed
mtias opened this issue Dec 19, 2019 · 21 comments · Fixed by #22368
Closed

Edit Site: Loading a specific context on a dynamic template #19257

mtias opened this issue Dec 19, 2019 · 21 comments · Fixed by #22368
Assignees
Labels
Needs Design Feedback Needs general design feedback. [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Status] In Progress Tracking issues with work in progress

Comments

@mtias
Copy link
Member

mtias commented Dec 19, 2019

Related to #19256.

There should be a way to load a specific context for a template (a "post" for single , a "category" for category, a series of posts for archive, etc) in preview mode. This could also be tied to the “browsing” mode as navigating by clicking would also effectively load a specific context (a page, post, category, etc) automatically.

In more sophisticated templates, like a complex magazine layout on the home, with multiple article queries, this should be both intuitive and flexible.

One consideration could be to always load some content by default (like latest post) and ensuring the display clearly indicates it's for preview purposes.

@dingo-d
Copy link
Member

dingo-d commented Jan 17, 2020

I have one question:

How will this be handled in the templates? Say I have a dynamic block that loads the latest custom post type posts.

How will this be possible with templates?

Because this content is dynamic, and it's changing, and when you save a block the content is saved in the DB, right? So you need a way to change these posts automatically when a new one is added. Is there going to be some handler that will enable this? Or some way to say to the editor render this block, but this block fetches the latest custom post type posts somehow.

The old way would be just writing a WP_Query and that's it. But the old ways are changing 😄

@shaunandrews
Copy link
Contributor

One quick thought I had was how to set context specifically for a Page Content area/block defined in a template:

Page Content Context

But it occurs to me that setting the context might need to be done on the document level — not on a block within the document. My mockup assumes the template's other parts (header, footer) aren't affected by the selected context. Maybe that's a true assumption, but I'm unsure and would love more input there.

@jasmussen
Copy link
Contributor

jasmussen commented Jan 27, 2020

But it occurs to me that setting the context might need to be done on the document level — not on a block within the document. My mockup assumes the template's other parts (header, footer) aren't affected by the selected context. Maybe that's a true assumption, but I'm unsure and would love more input there.

Great thought! But thank you for showing the idea regardless — your mockup helps explore one path and suggest others! 👏

And yes, it does seem like it's worth being able to set/change context in a more global sense. In this case you tackled the most difficult context — a homepage is just a Page, until it is set to be a Homepage elsewhere in the interface.

It would be simpler if you opened up an "Archives" page in the template editor (CC: @epiqueras), in this case we could perhaps presume that the context would be for that of an archive page, and blocks in the editor made aware of that?

@epiqueras
Copy link
Contributor

It would be more intuitive if the page had an archive Query block somewhere. Just like archive PHP templates can choose where to render the archive loop, you should be able to move the archive loop in block templates while using other parts of the template for static content or fixed posts/pages.

@mtias
Copy link
Member Author

mtias commented Mar 11, 2020

I think the context of loading a post / page / category to the vanilla templates has to be broader in scope. I'd imagine it could sit in the header itself:

image

That would let you browse different posts / pages / categories / etc depending on what template you are editing.

@shaunandrews
Copy link
Contributor

I tried a few different ideas for the Context menu; The first is trying to mimic the Template dropdown, using flyout submenus:

Context Menu

The, I tried adapting the Link UI:

Context Menu - Link UI

One concern I have it how this would work on smaller screens. At some point, there won't be enough horizontal space for the Context menu. The first solution that came to mind was to add the second toolbar, like we do currently for block toolbars on mobile screens:

image

@shaunandrews shaunandrews added Needs Design Feedback Needs general design feedback. and removed Needs Design Needs design efforts. labels Mar 11, 2020
@mtias
Copy link
Member Author

mtias commented Mar 11, 2020

Reusing the URL Link interface would make sense for me, it'd just filter down to the things that can actually be shown for the given template (pages for page, posts for single, etc, following the theme cascade).

In terms of spacing, I think we'll eventually coalesce into something like this for Template / Content:

image

The regular editor (not the site editor) could also just keep the Content part which would allow us to relocate the permalink control from the title once and for all.

@mtias
Copy link
Member Author

mtias commented Mar 11, 2020

Of course, for that we need to handle the top-toolbar better.

@jasmussen
Copy link
Contributor

As a strawman principle, the top toolbar could be permanently stacked on all breakpoints for this to happen. By "strawman" I mean this idea can serve as a baseline unless better ideas come around.

With regards to the mobile experience, I would recommend taking a look at how Google Docs mobile works. When you open a document, you see the title and sharing options, and an edit button. It's essentially in a "view only" state. When you click the edit button, the title/toolbar disappears and makes room for edit controls.

@ockham
Copy link
Contributor

ockham commented Apr 22, 2020

I find the top toolbar quite intuitive, but I wonder if it can indeed capture more complex cases such as described by @mtias:

In more sophisticated templates, like a complex magazine layout on the home, with multiple article queries, this should be both intuitive and flexible.

Using the top toolbar would probably come with the tradeoff of not allowing to create such layouts easily, wouldn't it?

I tend to agree with @epiqueras (#19257 (comment)) that a block-based approach (i.e. query blocks for archives, categories, etc) would mimic better what theme authors can currently do in PHP.

Since we might end up adding such query blocks for increased flexibility anyway, I think the top toolbar would become a bit arbitrary, connecting one designated area of the page to that query (while still allowing other query blocks in order to build more complex layouts). That raises the question why we would want to emphasize one area (and query) at all. Do we think it would help people build a better mental model? (But again, wouldn't it come at the tradeoff that more complex layouts are less easily feasible/conceivable?)

If we want to limit a given template (e.g. limit a category template to only categories, a single template to only posts/pages etc), we could do so by contextually limiting the available choice of query blocks in the block picker.

@epiqueras
Copy link
Contributor

Reusing the URL Link interface would make sense for me, it'd just filter down to the things that can actually be shown for the given template (pages for page, posts for single, etc, following the theme cascade).

In terms of spacing, I think we'll eventually coalesce into something like this for Template / Content:

image

The regular editor (not the site editor) could also just keep the Content part which would allow us to relocate the permalink control from the title once and for all.

I think this works great.

I find the top toolbar quite intuitive, but I wonder if it can indeed capture more complex cases...

The Query block will allow you to craft a WP_Query for its loop through its attributes. The renderer builds a WP_Query from the visited URL. So, while the Query block will be useful for complex layouts with multiple custom queries, we still need a sort of implicit Query block wrapping the whole template with its attributes dynamically computed from the URL the template is rendering on. The interface discussed here is for testing how your template renders under different URLs/queries.

@ockham
Copy link
Contributor

ockham commented May 8, 2020

Maybe it would make sense to start implementing content loading without the UI (as long as that's not final)? We could use routes or query args to point to the context we want to load (also see #22238).

@epiqueras
Copy link
Contributor

Yeah, that's a good idea.

@mtias
Copy link
Member Author

mtias commented May 11, 2020

It might make sense to pause this one for a little bit while the main navigation work gets established — there's a world in which loading a specific context is just navigating to that "edit page" route.

@mtias mtias added the [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later label May 11, 2020
@epiqueras
Copy link
Contributor

The infrastructure/block level work will be the same. We still need a way to load and render "that page".

@mtias
Copy link
Member Author

mtias commented May 12, 2020

I mean there's already a way to load "that page": post.php?post={ page_id OR template_id }&action=edit

@epiqueras
Copy link
Contributor

Yeah, but we also need to support queries, not just specific posts.

@ockham
Copy link
Contributor

ockham commented May 12, 2020

@mtias We were hoping to prioritize work on this issue (without the UI) since we think it's one of the more crucial parts for an MVP that will allow users to edit at least their front page in a WYSIWYG-y way 😄

@mtias
Copy link
Member Author

mtias commented May 12, 2020

@ockham I am confused :) I think what we need is to load the FSE version of the editor when you edit a wp_template part and that should handle things?

@epiqueras
Copy link
Contributor

I think he's thinking about how we change the global block context within the site editor.

I mean there's already a way to load "that page": post.php?post={ page_id OR template_id }&action=edit

E.g., that should load postId and postType into the root context.

Similarly, queries should be loaded so that placeholder Query blocks can use the queries.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label May 14, 2020
@ockham
Copy link
Contributor

ockham commented May 18, 2020

I think he's thinking about how we change the global block context within the site editor.

Yeah, exactly. (Sorry for not having been clear.)

I mean there's already a way to load "that page": post.php?post={ page_id OR template_id }&action=edit

E.g., that should load postId and postType into the root context.

Similarly, queries should be loaded so that placeholder Query blocks can use the queries.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Design Feedback Needs general design feedback. [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants