Use YAML with variables

前端 未结 5 1032
你的背包
你的背包 2020-11-28 22:47

Are variables within YAML files possible? For example:

theme:
  name: default
  css_path: compiled/themes/$theme.name
  layout_path: themes/$theme.name
         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 23:14

    Rails / ruby frameworks are able to do some templating ... it's frequently used to load env variables ...

    # fooz.yml
      foo:
        bar: <%= $ENV[:some_var] %>
    

    No idea if this works for javascript frameworks as I think that YML format is superset of json and it depends on what reads the yml file for you.

    If you can use the template like that or the << >> or the {{ }} styles depending on your reader, after that you just ...

    In another yml file ...

    # boo.yml
    
    development:
      fooz: foo
    

    Which allows you to basically insert a variable as your reference that original file each time which is dynamically set. When reading I was also seeing you can create or open YML files as objects on the fly for several languages which allows you to create a file & chain write a series of YML files or just have them all statically pointing to the dynamically created one.

提交回复
热议问题