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

Include from within and include #3

Closed
nhall opened this issue Jul 22, 2015 · 1 comment
Closed

Include from within and include #3

nhall opened this issue Jul 22, 2015 · 1 comment

Comments

@nhall
Copy link

nhall commented Jul 22, 2015

Is there a way to include a partial file from within another partial? I'd like to include a repeating sub component from within a component partial.

hello.html

<!DOCTYPE html>
<h1>Hello World!</h1>
{{ include('/path/to/include/message.html', {"name": "Joe Bloggs"}) }}

message.html

<p>Good morning, {{ name }}!</p>
<p>Here are the things you need to do today:</p>
<ul>
    {{ include('/path/to/include/todo.html', {"task": "Task 1"}) }}
    {{ include('/path/to/include/todo.html', {"task": "Task 2"}) }}
    {{ include('/path/to/include/todo.html', {"task": "Task 3"}) }}
</ul>

todo.html

<li>{{ task }}</li>

Desired Result:

<!DOCTYPE html>
<h1>Hello World!</h1>
<p>Good morning, Joe Bloggs!</p>
<p>Here are the things you need to do today:</p>
<ul>
    <li>Task 1</li>
    <li>Task 2</li>
    <li>Task 3</li>
</ul>
@stowball
Copy link
Owner

This can be achieved out of the box, but you might not be able to use the includesDir option.

With the following folder structure:

  • hello.html
    • includes/message.html
    • include/todo.html

You could use:

hello: {
  src: 'hello.html',
  dest: 'dist/hello.html'
}

where hello.html is

<!DOCTYPE html>
<h1>Hello World!</h1>
{{ include('includes/message.html', {"name": "Joe Bloggs"}) }}

message.html is

<p>Good morning, {{ name }}!</p>
<p>Here are the things you need to do today:</p>
<ul>
    {{ include('todo.html', {"task": "Task 1"}) }}
    {{ include('todo.html', {"task": "Task 2"}) }}
    {{ include('todo.html', {"task": "Task 3"}) }}
</ul>

and todo.html is:

<li>{{ task }}</li>

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

No branches or pull requests

2 participants