1

您好,我创建应用程序,我现在需要定义新布局,我在 grunt 文件中使用此代码

assemble: {
  pages: {
    options: {
      flatten: true,
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/default.hbs',
      data: '<%= config.src %>/data/*.{json,yml}',
      partials: '<%= config.src %>/templates/partials/{,*/}*.hbs'
    },
    files: {
      '<%= config.dist %>/': ['<%= config.src %>/templates/pages/*.hbs']
    }
  }
},

现在我阅读了文档http://assemble.io/docs/Layouts.html并输入了这样的必要代码。

assemble: {
  pages: {
    options: {
      flatten: true,
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/default.hbs',
      data: '<%= config.src %>/data/*.{json,yml}',
      partials: '<%= config.src %>/templates/partials/{,*/}*.hbs'
    },
    files: {
      '<%= config.dist %>/': ['<%= config.src %>/templates/pages/*.hbs']
    }
  },
  simple: {
    options: {
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/simple.hbs',
      data: '<%= config.src %>/data/*.{json,yml}',
      partials: '<%= config.src %>/templates/partials/{,}*.hbs'
    },
    files: {
      '<%= config.dist %>/': ['<%= config.src %>/templates/pages/simple/*.hbs']
    }
  }
},

基本上,我声明新布局简单,并尝试强制生成的模板位于同一目录中,但结果是 - dist/src/templates/pages/simple/name_of_file.html 此代码在默认情况下有效,但在其他布局中无效。

有什么帮助吗?这是否可能我有解决方法,但会很高兴完成这些事情。

没关系,我找到了解决方案

assemble: {
  pages: {
    options: {
      flatten: false,
      expand: true,
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/default.hbs',
      data: '<%= config.src %>/data/*.{json,yml}',
      partials: '<%= config.src %>/templates/partials/{,*/}*.hbs'
    },
    files: [
      {expand: true, cwd: '<%= config.src %>/templates/pages/', src: '**/*.hbs', dest: '<%= config.dist %>/', ext: '.html'}
    ]
  },
  simple: {
    options: {
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/simple.hbs'
    },
    files: [
      {expand: true, cwd: '<%= config.src %>/templates/pages/simple/', src: '**/*.hbs', dest: '<%= config.dist %>/', ext: '.html'}
    ]
  }
},
4

1 回答 1

1

我在这里找到了一个解决方案就是答案

assemble: {
  pages: {
    options: {
      flatten: false,
      expand: true,
      assets: '<%= config.dist %>/assets',
      layout: '<%= config.src %>/templates/layouts/default.hbs',
      data: '<%= config.src %>/data/*.{json,yml}',
      partials: '<%= config.src %>/templates/partials/{,*/}*.hbs'
    },
    files: [
      {expand: true, cwd: '<%= config.src %>/templates/pages/', src: '**/*.hbs', dest: '<%= config.dist %>/', ext: '.html'}
    ]
  },
  error: {
    options: {
      flatten: false,
      assets: '<%= config.dist %>/assets',
      data: '<%= config.src %>/data/*.{json,yml}',
      layout: '<%= config.src %>/templates/layouts/error.hbs'
    },
    files: [
      {expand: true, cwd: '<%= config.src %>/templates/error-pages/', src: '**/*.hbs', dest: '<%= config.dist %>/', ext: '.html'}
    ]
  },
  login: {
    options: {
      flatten: false,
      assets: '<%= config.dist %>/assets',
      data: '<%= config.src %>/data/*.{json,yml}',
      layout: '<%= config.src %>/templates/layouts/login.hbs'
    },
    files: [
      {expand: true, cwd: '<%= config.src %>/templates/login-pages/', src: '**/*.hbs', dest: '<%= config.dist %>/', ext: '.html'}
    ]
  }

我创建了 2 个新布局,一个用于错误页面,一个用于登录页面,所有页面都在同一个目录中生成。

于 2014-05-06T20:02:15.807 回答