Problem with linking assets

To follow up with all the information mentioned before, I would like to notice that specifying subdirectory or a file in a subdirectory in .scpages does not seem to find <link> assets, such as .css and .js files.
For example:

root/index.html
root/assets/js/script.js
root/assets/css/style.css
root/subdirectory/subdirectory/page.html

The page.html is not receiving any styling when viewed via ?=scpage and specified in .scpages. The paths are written correctly because I do not have any problems accessing the page.html when I quit Sitecake. The <link> path looks like this:
<link rel="stylesheet" href="../../assets/css/style.css">

I am running latest Sitecake 2.4.4 on Apache.

Should I change something in the Sitecake configuration in order to solve my problem?

There is no option to edit the post. So, perhaps you could enable it in Discourse.
To add a bit more details to my previous post:

  1. The complete folder structure looks like this:

    root/sitecake/
    root/sitecake.php
    root/index.html
    root/assets/js/script.js
    root/assets/css/style.css
    root/subdirectory/subdirectory/page.html

  2. Instead of ?=scpage I have meant sitecake.php?scpage= .

  3. When I open the Devtools in Chrome I see 404 file not found error on all correctly referred .css and .js files. But when I open devtools->application->frames I can see the scripts and stylesheets folders with all the required .css and .js files, but there files have no content. Only contentmanager.nocache.js, pagemenager.2.4.4.js and pagemanger.2.4.4.css have content.

Hi, can you send PM to me with site url and sitecake password so I can check it out.
Thanks

Can you explain in a more detail how exactly .scpages work?

All the assets on all of my pages work without any errors - paths to the assets are correct. But, when I login into Sitecake, all the assets on pages specified in .scpages file have broken paths.

Meaning this assets reference is not working in Sitecake:

But this one works:
<link rel="stylesheet" href="assets/css/style.css">
Does Sitecake thinks that all the .scpages are in root? Why would it do that?

Modifying the paths everytime I want to use Sitecake is extremely inconvenient.

Hi,

linking assets has nothing to do with .scpages. Sitecake is creating draft files that it works with. Draft files are located in sitecake-temp/<random-char-sequence>/draft/ directory. When loading page in edit mode you are actually accessing sitecake.php file and sitecake renders page as it is except urls to images and files which sitecake knows how to handle. So if you link your css as ../../assets/css/style.css, when accessing sitecake.php, assets are requested from <site-root>/../../assets/css/style.css which doesn’t exist. Try to link you css file relative to site root like /assets/css/style.css. That should work.

Thanks.

As I have said in the previous post:

If I modify all the paths to assets in all of the subdirectories they will work with Sitecake, but when I quit Sitecake the paths will remain broken. Meaning:

./assets/css/style.css - will work with Sitecake, but will not work when I quit it
../../assets/css/style.css - will not work with Sitecake, but will work when I quit Sitecake

It will make more sense to create multiple sitecake.php files. One in root and others in each subdirectory respectively. This (presumably) will not mess with paths.

For now, I only see Sitecake being used with files only located in root directory, because .scpages thing is clearly not working properly or expecting the user to have such folder structure:

root/sitecake/
root/sitecake.php
root/index.html
root/another-page.html
root/another-page-2.html
root/another-page-3.html
root/assets/js/script.js
root/assets/css/style.css

This folder structure is not really working when you have more than 20 .html files and want to organise them in folders.

Please read my post until the end, so you will not end up suggesting the same thing what I wrote before.

Hi,

I assumed that your site is in root domain. What is url to your site? (if it’s public you can send it via PM)
Also, I didn’t use dot (./) in front of path, I just used forward slash (/). If your site is in root domain eg. www.example.com, using /assets/css/style.css will certainly work.
If you are on localhost in a subdirectory, you should use full url.
So for example, if you are accessing your site via http://localhost/my-site/, you could use /my-site/assets/css/style.css, but make sure you adjust your paths before uploading to production.

Pay attention that paths in my both examples starts with / and not ./

Also, once again, .scpages doesn’t have anything to do with how you link your assets in template. It should be used to tell sitecake which physical files on your server that aren’t in site root dir should be considered as pages by sitecake.

As for creating multiple sitecake.php files in subdirectories wouldn’t work (at least it was never tested). If you insist to leave relative urls to assets, you could copy asset dir in each subdirecotry, but when in edit mode, pages would load ones from site root dir. This would only be needed for css and js files since sitecake knows how to handle images and files.

Hello @predragleka and @predragleka,

I am facing a similar issue with images (i am almost sure that the same thing would happen with files):
When I duplicate a page from root in a subdirectory doing this : Duplicate -> Details -> File name on the server. Shows up in the url and enter : “sub-page/newpage.html”, the folder and the page are created. Then I add an image in this new page, I publish but the image doesn’t show up outside the edit mode.

It appears that the generated path of the image in the source is missing the first ‘/’ : src=“images/…” .
How can I modify the sitecake code to make it looking at the image root folder and not the current sub-folder.
I have tried modifying the Site.php file but I ended with that path /sitecake-temp/r5ac576c8d26f4/draft/images/ in the html file. It would be great to have the generated path like this : src="/images/…"

Thank you for your help,
Romain

Sorry, don’t take it into account, I have found the solution in the documentation, just had to set the parameter $app[‘pages.use_document_relative_paths’] to true.

Hi, glad you figured it out

@predragleka, I have a question about the hash part inserted in the uploaded pictures : do you think that I can remove this particule, -sc[0-9a-f]{13}, in all lines about images and files in Site.php in order to remove the inserted hash part in image names ? How can I do it in order to keep the ‘sitecake way’ ?

Currently these needs to stay. We are planing to remove this in future, but for now sitecake needs that part of name tobe able to separate uploaded from images that were originally in HTML.

Ok can you give me a date for the update ?

Unfortunately not for that one. Not sure when it’s going to be implemented.

Hello @predragleka,

One month ago, Nik told me that it will be implemented in next release : > Regarding your ‘uglified’ image links ticket, we decided to change that, so in next release images will be with clear names without hashes.

Anyway, even if it’s not for this particular feature, next version seems to be full of great features, so I would need to know when you plan to release v3 ?