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

Only able to use top level elements in data.json for pattern parameter keys #189

Closed
theorise opened this issue Nov 17, 2015 · 6 comments
Closed

Comments

@theorise
Copy link

If I try to use any nested element inside the data.json for a pattern include, I get [SyntaxError: Unexpected token .] and Warning: Invalid template! Template should be a "string" but "undefined" was given as the first argument for mustache#render(template, view, partials) Use --force to continue.

The build does not fail, but the offending patterns are broken.

data.json:

"toplevel" : "300,00",
"price": {
    "old": "250,00",
    "new": "75,00"
}

pattern.mustache:

<span class="price {{styleModifier}}">
    {{price.old}}
</span>

pattern include call examples that throw the error:

{{> atoms-price:new(price.old: "75,00" ) }}
{{> atoms-price:new(price.old: "{{price.new}}" ) }}

If I use the toplevel value, the above works as expected.

@bmuenzenmeyer bmuenzenmeyer changed the title Only able to use top level elements in data.json for pattern includes Only able to use top level elements in data.json for pattern parameter keys Nov 23, 2015
@bmuenzenmeyer bmuenzenmeyer self-assigned this Nov 23, 2015
@bmuenzenmeyer
Copy link
Member

Hey @dmolsen

If you happen to have an up-to-date copy of PL PHP that you could test this on, I'd appreciate it. I am fairly certain it would be an enhancement to PL NODE in that patternParameter keys were not built to support mustache:

{{> atoms-price(price.old: "$100" ) }}

@bmuenzenmeyer bmuenzenmeyer removed their assignment Nov 25, 2015
@dmolsen
Copy link
Member

dmolsen commented Dec 1, 2015

@bmuenzenmeyer -

PL PHP doesn't support mustache in patternParameter keys either. That said, it is just a simple find and replace so I can get the example working with a small tweak to the initial example. Mustache tends to fall on its face using mustache tags in a pattern parameter. This is because Mustache is just looking for the closing bracket. It doesn't understand nesting. Instead we need to define a different delimiter for the pattern partial. So the example should look like:

{{> atoms-price:new(price.old: "75,00" ) }}
{{=<% %>=}}
<%> atoms-price:new(price.old: "{{ price.new }}" ) %>
<%={{ }}=%>

That produces the expected results for me in the dev version of PL2.

@bmuenzenmeyer
Copy link
Member

Sorry Dave but I don't understand this syntax

{{=<% %>=}}

<%={{ }}=%>

Are these working in isolation? In tandem? The first looks inverted, the second just empty {{ }} inside a different delimiter. My mind is soupy from asp.net perhaps.

Either way, I doubt this is making it into v.1.0.0

@dmolsen
Copy link
Member

dmolsen commented Dec 3, 2015

The = sets a delimiter. Eg what the mustache parser will see as a valid mustache tag. The first call changes the delimiter from {{ }} to <% %>. That way the mustache var in the pattern parameter doesn't get parsed and is instead seen just as a string. The second call switches the delimiter back.

More info:
https://mustache.github.io/mustache.5.html

On Dec 3, 2015, at 9:26 AM, Brian Muenzenmeyer [email protected] wrote:

Sorry Dave but I don't understand this syntax

{{=<% %>=}}

<%={{ }}=%>

Are these working in isolation? In tandem? The first looks inverted, the second just empty {{ }} inside a different delimiter. My mind is soupy from asp.net perhaps.


Reply to this email directly or view it on GitHub.

@bmuenzenmeyer
Copy link
Member

Oh!!!! Cool 💃 👯

@stale
Copy link

stale bot commented Oct 2, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the needs response label Oct 2, 2017
@stale stale bot closed this as completed Oct 9, 2017
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

3 participants