In a new file template can I add an import to a file in root directory? - Independent current directory?

Well for my current react project there's a lot of "automatic" code that happens. It is a react mobx, with material ui as component library application.

 

Both libraries use HOC function/classes to provide data to the actual objects. Thus a class would look like:

 

```

export ${NAME} withStyles(styles)(inject()(observer(class ${NAME} extends React.Component {
    render() {
    }
})));

```

 

This works, however I still have to manually add the path to the styles (jss) file. This file is located in the root of the project, and is "always" the same. It would be useful if I could let the file template resolve this automatically:

 

```

const styles = import "../styles"; //or: "../../styles" etc, based on the current relative directory.

```

 

Is this possible?

0
1 comment

You can try using $DIR_PATH macro (that returns current file dir relative to project root), transforming the path to relative using java string methogs. For example:

#set( $dir = $DIR_PATH.replaceAll("([^/]*)", "."))

...

const styles = import "$dir/styles";

0

Please sign in to leave a comment.