question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Add `relativePath` or `themePath` to `Asset`

See original GitHub issue

Terms

Summary

Asset currently has a path() function that returns the full, absolute path to the asset. Sometimes the path relative to the theme directory is also needed, as for add_editor_style. Currently, additional code/library is needed to get the path relative to theme directory from the absolute path returned by the path() function. It would be nice if also a function is added that returns the path to asset relative to the (Sage) theme directory.

Motivation

Why are we doing this?

Sometimes the path relative to the theme directory is also needed.

What use cases does it support?

add_editor_style requires either an URI (that currently cause an issue post-processing CSS in Gutenberg editor to rewrite URLs relative to stylehsheet) or a path to a local file relative to the theme directory (that doesn’t cause this issue).

What is the expected outcome?

Elimination of additional code/library for making the absolute asset path (from path()) relative to the theme directory path, so it can be used by functions like add_editor_style.

Potential conflicts / foreseeable issues

One more API function in acorn, paths and their handling shouldn’t change in the foreseeable future, so once the code (and tests) for a theme-directory-relative path function is in place, no changes should be expected any time soon. As this functionality would be requires in any theme that adds the frontend styles in the expected way (using add_editor_style), this should justify adding such an additional function.

Additional Context

https://discourse.roots.io/t/absolute-domain-relative-path-for-asset-urls-in-css/23121/4

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
strarsiscommented, Jul 10, 2022

With the newly added Asset::relativePath function this can be even further simplified:

namespace App;

use function Roots\asset;

add_action('after_setup_theme', function () {
    // Add frontend styles as editor styles
    // Must be added by relative path (not remote URI)
    // (@see https://core.trac.wordpress.org/ticket/55728#ticket)
    $relCssPath = asset('app.css')->relativePath(get_theme_file_path());
    add_editor_style($relCssPath);
});

(Discourse discussion)

Great work @QWp6t, thanks!

0reactions
QWp6tcommented, Jul 8, 2022

Config option for Roots\Acorn\Filesystem\Filesystem fixed in Acorn v2.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request: Add `relativePath` or `themePath` to `Asset` - roots ...
Feature Request : Add `relativePath` or `themePath` to `Asset` ... Asset currently has a path() function that returns the full, absolute path to...
Read more >
Allow custom theming · Issue #69 · SassDoc/sassdoc - GitHub
I thing an important feature would be to all the user to use a ... SassDoc would copy theme.path + '/assets' in the...
Read more >
Relative Path plugin - October CMS
Relative file path to theme assets. While the |theme filter returns an address relative to the active theme path of the website. The...
Read more >
[Request]:Relative path for asset imports
I have entered a Feature Request for relative path when the source assets are stored within the project directory. Cheers! Doug_Richardson ...
Read more >
Unity Cloud Build Feature Requests
Unity Cloud Build Feature Requests · 1. Allow us to add arbitrary values to the build manifest from our scm webhooks via the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found