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 attaching libraries, js, css with hook_theme. #6859

Open
laryn opened this issue Feb 27, 2025 · 2 comments
Open

Allow attaching libraries, js, css with hook_theme. #6859

laryn opened this issue Feb 27, 2025 · 2 comments

Comments

@laryn
Copy link
Contributor

laryn commented Feb 27, 2025

Description of the need

During the dev call today, we discussed potential benefits of allowing the attachment of libraries, js, css with hook_theme, rather than having to manually add them with backdrop_add_library() within a preprocess function, for example.

Proposed solution

Allowed #attached values to be used with hook_theme implementations, so that CSS and JS can be specified and be automatically added (only when the theme implementation is actually used). This will allow an easy way to specify libraries, JS and CSS and have it optimized to be used only when needed. Alters will also allow other implementations to make adjustments if needed.

@indigoxela
Copy link
Member

indigoxela commented Mar 7, 2025

Allowed #attached values to be used with hook_theme...

Hm, #attached is commonly used with forms or elements (renderable arrays), but in info-hooks? 🤔 @laryn do you have an example, where #attached also works with existing info hooks?

Or, do you mind to elaborate, why you can't attach libs within the actual theme implementation?

@laryn
Copy link
Contributor Author

laryn commented Mar 10, 2025

I think this would probably be a new way of using it. We had some discussion of it here that fleshed it out a bit, a few weeks ago:

I am hoping to be able to make a PR for this but if people have opinions in the meantime, this is the place to collect and discuss them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants