RejectedSoftware Forums

Sign up

diet include path

Some questions about diet templates placement:

Usually we have diet templates in views/ folder and they are found when we do include or extend in other diet template file, but not in string. I have foo.dt with content include bar, then do dst.compileHTMLDietFile("foo.dt") and it works as expected. Then I do dst.compileHTMLDietString("include bar") and it fails with 'Missing include input file'. Is it possible to achieve the same interpretation as the contents of the file and the string argument? If no, how to modify template, passed to compileHTMLDietString(), to have it worked?

Is this possible to change default views/ directory to another one?

Re: diet include path

On Thu, 16 Feb 2017 14:42:36 GMT, Alexey Kulentsov wrote:

Some questions about diet templates placement:

Usually we have diet templates in views/ folder and they are found when we do include or extend in other diet template file, but not in string. I have foo.dt with content include bar, then do dst.compileHTMLDietFile("foo.dt") and it works as expected. Then I do dst.compileHTMLDietString("include bar") and it fails with 'Missing include input file'. Is it possible to achieve the same interpretation as the contents of the file and the string argument? If no, how to modify template, passed to compileHTMLDietString(), to have it worked?

This is currently not directly possible, mostly because the file extension gets extracted from the root template file name. However, as long as the list of possible include and base template files is known, you should be able to achieve the same effect manually using compileHTMLDietStrings:

import diet.input, diet.html;
alias myCompileDietString(string contents, ALIASES...) =
    compileDietStrings!(Group!(
            "main.dt", contents,
            "layout.dt", import("layout.dt"),
            "bar.dt", import("bar.dt")
        ), ALIASES);

(disclaimer: not tested)

Is this possible to change default views/ directory to another one?

Yes, you can use stringImportPaths "path1" "path2" ... in dub.sdl (or "stringImportPaths": ["path1", "path2", ...] in dub.json) to define the directories that get searched for Diet templates. If you define this, you'll also have to explicitly specify the "views" folder if you still want to use that.

Re: diet include path

On Mon, 20 Feb 2017 19:42:03 GMT, Sönke Ludwig wrote:

... Is it possible to achieve the same interpretation as the contents of the file and the string argument? If no, how to modify template, passed to compileHTMLDietString(), to have it worked?

This is currently not directly possible, mostly because the file extension gets extracted from the root template file name.

Is this possible to make compileHTMLDietString() version with template file name passed as parameter? With FILE default value it will be reasonable I think.

However, as long as the list of possible include and base
template files is known, you should be able to achieve the same effect manually using compileHTMLDietStrings:

import diet.input, diet.html;
alias myCompileDietString(string contents, ALIASES...) =
    compileDietStrings!(Group!(
            "main.dt", contents,
            "layout.dt", import("layout.dt"),
            "bar.dt", import("bar.dt")
        ), ALIASES);

(disclaimer: not tested)

Ok! I will think about such approach but for first sight it seems to be overkill for my task. I am trying to implement component system and make each component to be encapsulated in one file (controller + template), but don't want to lost possibility to use diet features like extends and includes. If user can make one-file components, but have to manage this Group template, it does not make the situation easier.

Is this possible to change default views/ directory to another one?
Yes, you can use stringImportPaths "path1" "path2" ... in dub.sdl (or "stringImportPaths": ["path1", "path2", ...] in dub.json) to define the directories that get searched for Diet templates. If you define this, you'll also have to explicitly specify the "views" folder if you still want to use that.

Thanks! In the meantime, I also found this, but it takes the time. Now I can have 2-file components like editUser.d + editUser.dt.
P.S. Lack of documentation is very bad side of vibe.d. This prevents easy entry into the technology and make it less popular.

Re: diet include path

On Tue, 21 Feb 2017 13:10:54 GMT, Alexey Kulentsov wrote:

On Mon, 20 Feb 2017 19:42:03 GMT, Sönke Ludwig wrote:

... Is it possible to achieve the same interpretation as the contents of the file and the string argument? If no, how to modify template, passed to compileHTMLDietString(), to have it worked?

This is currently not directly possible, mostly because the file extension gets extracted from the root template file name.
Is this possible to make compileHTMLDietString() version with template file name passed as parameter? With FILE default value it will be reasonable I think.

Now implemented: 323cd41