Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Adding complex dynamic data to helpers and sub-templating from custom helpers #68

Closed
jslegers opened this issue Jul 3, 2014 · 3 comments

Comments

@jslegers
Copy link
Contributor

jslegers commented Jul 3, 2014

I'm currently experimenting with the following features.

Sub-templating

Syntax :

<div class="site-body">
    <div class="site-center">
        <div class="cell">
            {{{template panel this name}}}
        </div>
    </div>
</div>

Explanation :

  • It includes a template called panel at this very spot
  • It passes the data for {{this}} and {{name}} to the template

Passing data to helpers

The problem with the syntax {{{template panel this name}}} is that it's rather restrictive in naming of parameters that are past to a subtemplate (or other helper).

To allow more custom naming, alternate syntaxes could be :

{{{template panel data=this&name=John}}}
{{{template panel data=this name=John}}}
{{{template panel data=this;name=John}}}
{{{template panel data=this,name=John}}}
{{{template panel data=this-name=John}}}

See also #44

The problem with these syntaxes, is distinguishing between what content should passed literally (eg. John) and what content should passed as a reference (eg. this). Variations on this syntax that add this distinction would be :

{{{template panel data=this&name="John"}}}
{{{template panel data=this&name='John'}}}
{{{template panel data={{this}}&name=John}}}
{{{template panel data=$this&name=John}}}
{{{template panel data=${this}&name=John}}}

As any content in between a beginning and end tag remains unparsed for custom helpers, there are nevertheless still many alternatives worth considering :

{{#template panel}}
<input type="array" name="data" value="{{this}}" />
<input type="string" name="name" value="John" />
<output type="string" name="panel" />
<!-- This syntax would even allow you to store the output -->
<!-- of the template as a variable named panel -->
{{/template}}
{{#template panel}}
<parameters>
    <array data="{{this}}" />
    <string name="John" />
</parameters>
{{/template}}
{{#template panel}}
<input>
    <array data="{{this}}" />
    <string name="John" />
</input>
<output>
    <string panel />
</output>
{{/template}}
{{#template panel}}
<template>
    <parameter data="{{this}}" />
    <parameter name="John" />
</template>
{{/template}}
{{#template panel}}
data : (array) {{this}}
name : (string) John
{{/template}}
{{#template panel}}
data = {{this}}
name = John
{{/template}}

Would you be interested in adding any of these syntaxes to the XaminProject/handlebars.php library? I am still considering which syntax to use for my own PowerTools project and I figured I might as well contribute the syntax I eventually choose to the XaminProject/handlebars.php project if anyone is interested.


EDIT :

See also handlebars-lang/handlebars.js#817

@JustBlackBird
Copy link
Contributor

@jslegers, the syntax, you proposed, is not compatible with Handlebars.js. I think there is no reason to implement a new complex arguments passing syntax. It is a step away from compatibility between PHP and JS versions of Handlebars.

@jslegers
Copy link
Contributor Author

jslegers commented Jul 3, 2014

@JustBlackBird :

That's a totally valid point.

I guess this issue should be raised at the handlebars.js community, so I did -> handlebars-lang/handlebars.js#817

@everplays
Copy link
Contributor

as main implementation rejected this proposal, I am closing this one too.

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

No branches or pull requests

3 participants