Skip to content

Possible solution to allowing dynamic include #2030

Open
@smaili

Description

@smaili

There's so many issues that are open regarding this I honestly am not sure which one (if any) is the main/active one so I'm creating a new ticket that I hope may offer a solution :)

As I understand correctly, the reason for currently not having the ability for dynamic includes is due to compilation. Assuming that is correct, I would like to propose allowing the use of dynamic include with the constraint that you must give some sort of compiler annotation that provides a list of all possible values of that dynamic include.

For example, say I have the template main.jade:

//- main.jade
-
    var name = '';
    if ( input === 'a' ) name = 'a';
    else if ( input === 'b' ) name = 'b';
    else if ( input === 'c' ) name = 'c';
    else name = 'd';

include /templates/#{ name }

In order to let the compiler know all of the possible files that may be included, we just include some kind of special annotation.

//- main.jade
-
    var name = '';
    if ( input === 'a' ) name = 'a';
    else if ( input === 'b' ) name = 'b';
    else if ( input === 'c' ) name = 'c';
    else name = 'd';

//- Give the compiler key/value list of possible values for each variable used in the include
include /templates/#{ name }//-{ name: [ 'a', 'b', 'c', 'd' ] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions