grunt-includes icon indicating copy to clipboard operation
grunt-includes copied to clipboard

Add ability to pass parameters

Open mmavko opened this issue 10 years ago • 7 comments

This is a feature request :)

I would like to do the following:

<!-- fileA.html -->
include "fileB.html?param1=value1&param2=value2"
<!-- fileB.html -->
<div>Value of "param1" is {$param1}</div>
<div>include "another/file/{$param2}"</div>

Though maybe URL query is not the best way to pass params since it requires manual URL encoding. Maybe JSON would be better:

<!-- fileA.html -->
include "fileB.html" {"param1":"value1","param2":"value2"}

Or just a list of (JSON.stringified?) arguments like this?

<!-- fileA.html -->
include "fileB.html" "value1" "value2"
<!-- fileB.html -->
<div>Value of "param1" is {$1}</div>
<div>include "another/file/{$2}"</div>

Thanks!

mmavko avatar Jan 06 '14 13:01 mmavko

Is #9 similar to what you want? If there is interest I don't have a problem implementing it.

vanetix avatar Jan 06 '14 15:01 vanetix

If I understand it correctly, what your talking in #9 is providing all templates (or some group of them based on task target) with a set of global params. This is good feature too, but what I'm talking about is the ability to provide a template with specific params for each inclusion. For example:

<!-- index.html -->
<div>
  include "wrapper.html" "content1"
</div>
<div>
  include "wrapper.html" "content2"
</div>
<!-- wrapper.html -->
<div class="wrapper">
  include "{$1}.html"
</div>

And this will include content1.html and content2.html.

mmavko avatar Jan 08 '14 09:01 mmavko

:+1:

dominikwilkowski avatar Aug 07 '14 00:08 dominikwilkowski

+1

xbonell avatar Sep 18 '14 10:09 xbonell

I'd be great if it was done in a json format kinda way so you could pass arrays.

If that was possible you could do something like this:

the call:

<div>
  include "your-snipper.html":{ name: "Bob", "tel": [ work: "555 732 284", home: "555 1937 736", mobile: "555 4762 1726" ] }
</div>

your-snipper.html

<div class="vcard">
  <p>{{ name }}</p>
  {% for number in tel %}
    <p>{{ number }}</p>
  {% endfor %}
</div>

But I'm just dreaming here :)

dominikwilkowski avatar Nov 14 '14 04:11 dominikwilkowski

I had the same question today and just came into this page, any news on that?

eporroa avatar Jun 30 '15 14:06 eporroa

+1

ghost avatar Mar 19 '16 11:03 ghost