Closed elemis closed 3 years ago
The @@webRoot
variable is set automatically. Just use it in your template wherever you need a relative path to the source root.
For example, the src
and href
attributes below both use @@webRoot
:
<!DOCTYPE html>
<html>
<head>
<link type=stylesheet src=@@webRoot/css/style.css>
</head>
<body>
<h1>Support Contact Info</h1>
<footer><a href=@@webRoot>Home</a></footer>
</body>
</body>
</html>
Depending on how deep your template is in the folder structure, the resulting HTML will look something like:
<!DOCTYPE html>
<html>
<head>
<link type=stylesheet src=../../css/style.css>
</head>
<body>
<h1>Support Contact Info</h1>
<footer><a href=../..>Home</a></footer>
</body>
</body>
</html>
For a working example that's part of a project, see: https://github.com/dnajs/data-dashboard/blob/main/src/web-app/html/doc-begin.html#L14-L18
I thought that would be the case but somehow it doesn't work for me.
This is the structure I have: dist/index.html dist/docs/index.html
But @@webroot output is same for both and is: "./" Though it's supposed to be "../" on files inside docs directory.
Maybe I'm missing something somewhere?
Here's a correctly working example of the @@webRoot
variable that is used in a template at two different levels:
website/root/index.html (higher) https://github.com/dnajs/dna.js/blob/main/website/root/index.html#L1
website/root/tutorial/index.html (deeper) https://github.com/dnajs/dna.js/blob/main/website/root/tutorial/index.html#L1
You may have encountered a bug that needs fixing, but it's hard to know without seeing code to replicate the problem.
One possibility (but it's just a wild guess) is that your gulpfile.js is actually running two separate tasks for the output, and the source root for each of the two tasks is the folder containing its respective index.html files.
Thank you for the example. I started from scratch and it worked!
I don't understand how @@webRoot works. Do I have to define it with @@include? Or does it work automatically depending on the directory level? If I have to define it, how can I make it work with nested partials? Can someone show an example please? Thanks.