mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

Question: Create nested folder from variable ? #1458

Closed cmoulliard closed 5 months ago

cmoulliard commented 5 months ago

Question

Can nunjucks create a directory structure as proposed hereafter if the variable passed include "/" ?

What we have within the skeleton of the templates project

ls -la qshift/templates/quarkus-extensions/skeletons/src/main/java 
total 0
drwxr-xr-x@ 4 cmoullia  staff  128 Feb  1 16:08 ${{values.java_package_name}}

What we declare => java_package_name=io/quarkus

Expected result

src/
  main/
    java/
      io/
       quarkus/
          Myfile.java

What we got

src/
  main/
    java/
      io/quarkus/
          Myfile.java
devoidfury commented 5 months ago

Nunjucks itself doesn't create files or directories at all, there's something else going on here and a lot of context missing from the question. It's not clear to me what's going on and I'm not sure how it's relevant to nunjucks.

cmoulliard commented 5 months ago

Your are right. That works doing that using backstage template - https://backstage.io/docs/features/software-templates/writing-templates/#the-templating-syntax

 id: hibernate-orm-rest-dataTemplate
      name: Generating REst...
      if: ${{ 'io.quarkus:quarkus-hibernate-orm-rest-data-panache' in parameters.extensions }}
      action: fetch:template
      input:
        url: skeletons/
        values:
          java_package_name: ${{ parameters.java_package_name }}
          java_package_path: ${{ parameters.java_package_name | replace(".", "/") }}