Jump to content

Local development and remote assets


leftblank
 Share

Recommended Posts

Hi,

I'm developing locally, but connecting to a remote database on my staging server, so I can see the correct content when I'm developing. All of my assets are uploaded through the admin on the staging server, and are therefore hosted on the staging server.

When I refer to an asset in a template, it is looking for that asset on my remote machine, so I therefore want to tell it to prepend the URL of my staging server in front of every asset path. Is there some global place I can do that? I don't fancy having to manually paste in a URL variable before every asset call in every template.

Thanks!

Link to comment
Share on other sites

How do you include your assets? Relative or absolute paths?

Have you tried using base href? Otherwise take a look at site/config.php You can add your own config variables an use them everywhere (e.g. in a template wire('config')->yourVariable)

  • Like 3
Link to comment
Share on other sites

Another option would be to add a small module that hooks Page::render and replaces the paths directly in the output... when running on localhost. It could replace it with something like this:

public function init() {
  if(wire('config')->httpHost == 'localhost') {
    $this->addHook('Page::render', $this, 'hookAfterPageRender'); 
  }
}

public function hookAfterPageRender($event) {
  $event->return = str_replace('/site/assets/files/', 'http://domain.com/site/assets/files/', $event->return); 
}
  • Like 6
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...