Multisite not loading CSS/assets?

Quick question, have been playing with multisite kirby with a single kirby/panel folder and the rest in sub folders of websites/domain. But no css is loading, it will if I put the assets folder in the root, but that defeats the object of having separate asset folders. It is like it is not picking up the path to assets. Anyone and ideas?

A picture might make it easier to visualise:

My site.php looks like this:

<?php

// /site.php

$kirby   = kirby();
$domain  = server::get('server_name');
$domains = array('test.dev', 'test2.dev');

if(in_array($domain, $domains)) {

  // custom roots
  $kirby->roots->site    = __DIR__ . DS . 'websites'. DS .  $domain . DS . 'site';
  $kirby->roots->content = __DIR__ . DS . 'websites'. DS .  $domain . DS . 'content';
  $kirby->roots->assets  = __DIR__ . DS . 'websites'. DS .  $domain . DS . 'assets'; 
  $kirby->roots->avatars = __DIR__ . DS . 'websites'. DS .  $domain . DS . 'assets'. DS . 'avatars';
  $kirby->roots->thumbs  = __DIR__ . DS . 'websites'. DS .  $domain . DS . 'thumbs';

  // custom urls
  
  $kirby->urls->index    = url::scheme() . '://' . $domain;	
  $kirby->urls->content  = $kirby->urls->index . DS .  'websites'. DS .  $domain . DS . 'content/';
  $kirby->urls->assets   = $kirby->urls->index . DS .  'websites'. DS .  $domain . DS . 'assets';
  $kirby->urls->avatars  = $kirby->urls->index . DS .  'websites'. DS .  $domain . DS . 'assets/avatars/';
  $kirby->urls->thumbs   = $kirby->urls->index . DS .  'websites'. DS .  $domain . DS . 'thumbs/';

}

What does it actually output as the path to the assets?

OK, if I echo:
__DIR__ . DS . 'websites'. DS . $domain . DS . 'assets';
I get:
/Users/russellbaldwin/Sites/multisite/websites/test.dev/assets
Which on a Mac looks OK?

And if I echo:
$kirby->urls->index . DS . 'websites'. DS . $domain . DS . 'assets'
I get:
/websites/test.dev/assets
Which also looks OK?

Can I provide any more info, a bit baffled.

What I actually wanted to know was what the css helper actually renders in the page:

<?= css('assets/css/whatever.css'); ?>

Apologies Sonja, I misunderstood :

For test.dev:
<link rel="stylesheet" href="http://test.dev/assets/css/index.css">

For test2.dev:
<link rel="stylesheet" href="http://test2.dev/assets/css/index.css">

Thanks, Russ, I’ll look into this as soon as I can.

Thanks Sonja, if you need anymore information let me know. It seems like it is not picking up the assets path from the site.php, of course it might not be picking up other stuff as well, but that is as far as I have got. Hopefully you will be able to reproduce it.

Russ

Does it render anything on the page with this setup?

As far as I can see all of the home page minus the CSS, same for About and Contact. Projects loads, but clicking ‘Project A’ gives an error file_get_contents(): Filename cannot be empty

Whoops\Exception\ErrorException /vendor/getkirby/toolkit/lib/media.php166

This is the same error for ‘Blog’.

This is on Kirby Version 2.5.2 starter kit, downloaded today.

If I move the assets folder from one of the sites to the root, all pages work as expected.

Just wondering if you have had any thoughts on this yet Sonja?

Hey Russ,

sorry, unfortunately, it slipped my mind after I got frustrated with being unable to get this setup to work at all for testing…

Maybe @lukasbestle can come to the rescue?

Thanks Sonja, maybe this can help, a link my test setup in a zip.
I’ve added an ‘_assets’ file in the multisite root. Rename this and it all seems to work OK. Remove that file and even though the assets exist in the individual site folders, it does not seem able to find assets.

Thanks for the zip. Unfortunately, I get the same result and no idea how to fix it :cry:

I see two issues:

  1. You are using DS in the URLs. This will work on all systems that use forward-slashes as directory separators, but not on Windows for example. Please use a simple / there. Of course you should still use DS for the roots.
  2. The $kirby->urls->assets is only used for the autocss/autojs feature and the avatars, not for simple executions of the css()/js() helpers. You need to prefix those manually or change your setup so that the assets are accessible from the URLs based on the domain root. Best way would be to point your web server at the websites/<domain> directories directly. Your index.php in those directories could then init some shared code like a global kirby directory.

Hi Lukas, thanks for taking a look but I’m not sure I understand what you are saying.

  1. Are you saying it does not work as I have it laid out? Can we have a shared kirby/panel (and maybe other e.g. plugins) folder with sub folders for domains. I was pointing the domains at the multisite folder/site.php and thinking that would point to sub folders, am I wrong?
  2. On both Unix or MacOS it is the same. Changing to ‘/’ alters nothing but I appreciate your point. The CSS and JS are loaded by autocss/autojs as they are the starter kit files. I’m also a bit confused about this, does this mean the ‘asset path’ cannot be used for images/fonts? Perhaps you have to set it manually in site.php?

Sorry if I’m not being very clear, hope you can help.

Anyone any thoughts? I’d really like to get this to work.

Sorry for the delay!

Your setup will work, but not exactly in the way you implemented it.
My recommendation: Use a directory structure like this:

kirby/
  ...
panel/
  ...
test.dev/
  assets/
    ...
  content/
    ...
  index.php
  kirby -> ../kirby
  panel -> ../panel
  site/
    ...
test2.dev/
  assets/
    ...
  content/
    ...
  index.php
  kirby -> ../kirby
  panel -> ../panel
  site/
    ...

Basically you have separate sites but use a global kirby and panel directory outside of the webroots. Those two directories are then linked into the sites using a symbolic link (ln -s ../kirby kirby).

It won’t change anything on Linux/macOS. But you should change it anyway. :slight_smile:

Kirby does not keep track of any other assets than autocss/autojs and avatars. It just doesn’t care at all where all other assets like images and fonts are stored. That’s why there is no configuration option for this – it wouldn’t get used anywhere.
If you use css('assets/css/whatever.css'), you just get a style tag with a URL that is relative to the site’s root URL, it doesn’t matter if you are pointing to the assets directory or a directory with a different name.

Thanks for all you help and explanations Lukas, it is appreciated.

I tried as you suggest with an alias back to the kirby and panel folders in multisite. (I moved the websites sub folder to the root.)

multisite
├── index.php
├── kirby
├── panel
├── site.php
├── test.dev
    ├── assets
    ├── content
    ├── index.php
    ├── kirby -> ../kirby
    ├── panel -> ../panel
    ├── site
    └── thumbs
└── test2.dev
    ├── assets
    ├── content
    ├── index.php
    ├── kirby -> ../kirby
    ├── panel -> ../panel
    ├── site
    └── thumbs
  1. If I point test.dev domain to where the real Kirby/Panel/site.php (multisite folder) I still get no CSS loading.
  2. If I point the test.dev domain to it’s actual folder (multisite/test.dev/) I get an error Fatal error: The site directory is missing in /xxx/xxx/Sites/multisite/kirby/kirby.php on line 536

Any ideas?

  • You should delete the index.php and site.php in the multisite directory. Those aren’t required for your setup.
  • Please point the server at the site’s subdirectories directly.

Oops, I forgot something. Please create a multisite/test.dev/site.php with the following contents:

<?php

$kirby = kirby();
$kirby->roots = new Kirby\Roots(__DIR__);