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

Background image: add support for relative theme path URLs in template and pattern files #62254

Open
ramonjd opened this issue Jun 4, 2024 · 4 comments
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.

Comments

@ramonjd
Copy link
Member

ramonjd commented Jun 4, 2024

Part of:

What problem does this address?

Since #61271, themes can define relative paths to background images in theme.json files.

The same functionality does not yet exist for other theme assets, namely:

  • template/template parts
  • patterns

For these assets, theme authors should be able to add relative paths to background images, for example, in Group block attributes.

This impacts the portability of themes.

What is your proposed solution?

Parse block attributes and replace the relative URIs with absolute URIs using get_theme_file_uri.

Where this is done — on the frontend or clientside — is to be decided.

#61401 is a working example that runs clientside, but it will be worth investigating whether backend pre-processing is viable pursuant to #61271.

Related

@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Jun 4, 2024
@annezazu
Copy link
Contributor

annezazu commented Jun 4, 2024

Just a quick alert to @WordPress/block-themers who I think will be excited to see this.

@creativecoder
Copy link
Contributor

A couple points of context:

  1. I think it would be best to solve this for all images, including both background images and regular <img src=> image tags at the same time.
  2. For templates and patterns, "bits" may serve as an alternative to relative urls, by dynamically replacing the current site domain and/or theme path in the url. See Bits: Dynamic replacement of server-provided content (tokens, "shortcodes 2.0") #39831 -- I don't think they're usable right now, but I believe this concept is being actively experimented with (cc @dmsnell @ellatrix )

@dmsnell
Copy link
Member

dmsnell commented Jun 5, 2024

For templates and patterns, "bits" may serve as an alternative to relative urls, by dynamically replacing the current site domain and/or theme path in the url. See #39831 -- I don't think they're usable right now, but I believe this concept is being actively experimented with (cc @dmsnell @ellatrix )

100% @creativecoder - thanks for the link. I tried to open up the ability to store Bits in Core for 6.6 but that may not happen (could still happen 🤞)

6.7 is a much bigger target for working Bits code.

@ramonjd
Copy link
Member Author

ramonjd commented Jun 5, 2024

Thanks for the context, folks.

6.7 is a much bigger target for working Bits code.

Great to hear. I'll try to keep with progress on it. It sounds it'd suit this use case perfectly. 👍🏻

I think it would be best to solve this for all images, including both background images and regular <img src=> image tags at the same time.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants