Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT: no such file or directory when passing local data using include #33

Open
neginbasiri opened this issue Oct 30, 2017 · 3 comments

Comments

@neginbasiri
Copy link

neginbasiri commented Oct 30, 2017

Hi all
I try to pass local data using include but getting error.

I confirm that this works
<%- include ../../components/content.blocks/two.column.content.ejs %>

However when I pass some local data along with include as bellow I get error

<%- include('../../components/content.blocks/two.column.content.ejs', {content: content}); %>

However I got error
ENOENT: no such file or directory, open 'C:\Projects\Nephele\src\UI\src\templates\layouts\avalon('..\components\content.blocks\two.column.content.ejs', {content: content});'

More Detail Code:

page.templates.js

const pages = [
    {
        title: 'Fleets',
        template: 'templates/pages/avalon/fleets.ejs',
        filename: 'fleets.html',
        inject: 'body',
        data: require('../templates/data/avalon/fleets.json')
    }
];

const pageTemplates = pages.map(page => new HtmlWebpackPlugin(page));

module.exports = pageTemplates;

webpack.config.js

const pageTemplates = require('./page.templates.avalon.js');
const webpack = require('webpack');
let config = require('../../webpack.config.js');

// Set entry point
config.entry.app = './scripts/brands/avalon.js';

// Load in page templates
config.plugins.push(...pageTemplates);

module.exports = config;

fleets.ejs

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title><%= htmlWebpackPlugin.options.title %></title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

     
</head>

<body>
    <%- include src/templates/layouts/avalon/fleets.layout.ejs %>
</body>

</html>


Fleet.layout.ejs

<% 
var data = htmlWebpackPlugin.options.data;
if (data) {  %>
<!-- Header -->
<%- include ../../components/avalon/header/header.ejs %>
    <div class="page-mask">
        <%- include ../../components/hero.image/hero.image.ejs %>
        <%- include ../../components/content.blocks/one.column.content.ejs %>
        <%- include ../../components/content.blocks/image.row.content.ejs %>
        <% if(data.twoColumnContent[0]){ 
            var content = data.twoColumnContent[0]; %>
            <%- include("../../components/content.blocks/two.column.content.ejs", {content: content}); %>
        <%}%>
       
        <%- include ../../components/content.blocks/title.button.content.ejs %>
        <%- include ../../components/footer/footer.ejs %>
    </div>
<%}%>
@relaxgo
Copy link

relaxgo commented Nov 10, 2017

I had same issue, because it install 1.x without version. you can reinstall it by yarn add ejs-compiled-loader@2.x or npm install ejs-compiled-loader@2.x. May be you need remove old first.

When you include child template with data by webpack, you may still have trouble. I got error that can't find include function. You can try <%- require('content.ejs')({ content: content })%>

@neginbasiri
Copy link
Author

neginbasiri commented Nov 16, 2017

@relaxgo Thanks for response. I can use local data now! You saved a lot of my time. The only issue I have now is webpack doesn't rebuild on ejs file changes. Any solution for that?

@suyi91
Copy link

suyi91 commented Apr 8, 2018

@relaxgo having the same issue for several days. Thanks for your solution, it works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants