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

Home Link block doesn't work well outside of menus #35926

Open
iandunn opened this issue Oct 25, 2021 · 11 comments
Open

Home Link block doesn't work well outside of menus #35926

iandunn opened this issue Oct 25, 2021 · 11 comments
Labels
[Block] Home Link Affects the Home Link Block [Block] Navigation Affects the Navigation Block [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@iandunn
Copy link
Member

iandunn commented Oct 25, 2021

What problem does this address?

Menus aren't the only place that people add links to the homepage. For example, a 404.html template could say:

This page doesn’t exist.
Go to the homepage, or try searching from the field below.

When used in that kind of context, the link is wrapped in an unnecessary li tag and there's no corresponding ul (which isn't valid HTML).

I could wrap the block in a ul, but then I have to add extra CSS to reverse its styles, so that it doesn't appear to be a list.

Related #32939

What is your proposed solution?

Add support for the tagName attribute, and default to li.

If the value is a, then just output the link without any wrapper element.

@iandunn iandunn added the [Block] Navigation Affects the Navigation Block label Oct 25, 2021
@carolinan
Copy link
Contributor

carolinan commented Oct 26, 2021

How are you adding the home link block outside the navigation block?
I did not think that was possible or intended, it is limited to the navigation block:
"parent": [ "core/navigation" ],

I also think adding a block inline inside a paragraph, to add a link to the home would be much more complicated than just selecting the text and adding the link?

@iandunn
Copy link
Member Author

iandunn commented Oct 26, 2021

Not in the editor, I'm adding it directly to my 404.html file.

<!--
  -- Right now, this is the least-bad way to get a dynamic link to the homepage (rather than hardcoding the URL).
  -- @link https://github.com/WordPress/gutenberg/issues/35926
  -- @link https://github.com/WordPress/gutenberg/issues/32939
  -->
<!-- wp:html -->
<div>
	Go to
	<ul class="is-inline"><!-- wp:home-link {"label":"the homepage","tagName":"div"} /--></ul>,
	or try searching from the field below.
</div>
<!-- /wp:html -->

Supporting tagName would fix the issue for my specific use case, but there's also the larger issue that the block "should" be able to be used outside a menu, IMO. So to fix that, we'd also need to allow the editor to add it outside a menu.

@iandunn
Copy link
Member Author

iandunn commented Oct 26, 2021

( that approach might break if a user edited it, but i'm building a custom theme for a specific site, not something that's meant to be distributed. a lot of the templates will be locked, at least until issues like this one are resolved )

@iandunn
Copy link
Member Author

iandunn commented Oct 28, 2021

A better way to solve this might be to allow template tags like {{ home_url }} (which would map to the PHP home_url() function). That would solve a much wider range of problems than just the specific problem with this block.

@mkaz suggested that in #31815 (comment)

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 18, 2023
@jordesign
Copy link
Contributor

jordesign commented Aug 18, 2023

Currently the Home Link block cannot be inserted outside the Nav (an issue which is raised here) which makes this issue not currently relevant. Accordingly I'll close it for now.

@jordesign jordesign closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2023
@iandunn
Copy link
Member Author

iandunn commented Aug 18, 2023

I think it can, I've done it before, which is how I ran into this issue. See my earlier comment for details.

@iandunn iandunn reopened this Aug 18, 2023
@carolinan
Copy link
Contributor

There is no tool yet that we can use in our code editors to verify if the markup is correct, not the way that we can lint JavaScript or PHP, so it is possible to write any code in the HTML file manually, but it doesn't mean it will work.

@jordesign
Copy link
Contributor

I'm inclined to agree with @carolinan - whilst it is possible to add the code manually into a template like that - it's certainly not the planned use-case, and wouldn't be expected to particularly work like that.

@carolinan
Copy link
Contributor

At the same time, the use case is clearly described; it just isn't a bug with this block, more a feature request.

If we treat it as a feature request, is it a duplicate of the dynamic token? #39831?
I am trying to think of which issues and current discussions may be closely related.

@iandunn
Copy link
Member Author

iandunn commented Aug 22, 2023

Yeah, #39831 seems related, and also #32939, #20966, and #21932 (and probably several others). Those may be alternative/better ways to solve this problem 👍🏻

From the perspective of a plugin dev, it does seems unexpected to me that something called a "home link" would be coupled so tightly to the nav block, rather than working as a standalone block. If #49282 removes the <li>, though, that works for me 👍🏻

Y'all are closer to the project than I am, so feel free to re-close this if that seems best to you. I just re-opened it because at the time I assumed it was closed based on a misunderstanding.

@carolinan
Copy link
Contributor

carolinan commented Apr 8, 2024

This developer use case should now be solvable with the block bindings API.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Apr 8, 2024
@carolinan carolinan removed their assignment Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Home Link Affects the Home Link Block [Block] Navigation Affects the Navigation Block [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants