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

Tag Params #881

Closed
mlrawlings opened this issue Oct 5, 2017 · 2 comments
Closed

Tag Params #881

mlrawlings opened this issue Oct 5, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@mlrawlings
Copy link
Member

mlrawlings commented Oct 5, 2017

New Feature

Description

Use the parentheses after the tag name to declare parameters that are available inside the tag body. The values of these parameters will be provided by the tag on which they are declared.

<mouse-position(mouse)>
  Mouse is at ${mouse.x}, ${mouse.y}.
</mouse-position>

Parameters should work like JS parameters and should support destructuring, etc.

<mouse-position({ x, y })>
  Mouse is at ${x}, ${y}.
</mouse-position>

Why

Currently a person creating a tag that needs to render its body and pass parameters has to create a transform of some sort to append these parameters to the renderBody function. Marko needs a standard way to introduce parameters to the body of a tag.

Marko already has tags that introduce variables into their body using the parenthesis that follow the tag name, so this maintains consistency with that approach:

<await(user from userPromise)>
   The user is ${user.name}!
</await>

<for(item in array)>
  <li>${item.id}</li>
</for>

Possible Implementation & Open Questions

This new behavior for the parentheses after the tag name conflicts with the current default for the parenthesis, which is for them to be considered arguments to pass data into the tag. This is being addressed in #878.

Because of the conflict, this will be implemented behind a feature flag for Marko 4. To enable the feature, you will set a flag in the marko-tag.json for a tag that needs to be able to receive parameters in its body.

{
  "feature-flags": [
    "tag-parameters"
  ]
}

The user of the tag will not have to do anything special. In Marko 5 (whenever that is) this behavior will be enabled by default.

@mlrawlings mlrawlings added blocked Cannot be completed before another issue. The blocking issue should be linked. status:todo type:feature A feature request labels Oct 5, 2017
@mlrawlings mlrawlings added this to the Tag Params milestone Oct 5, 2017
@mlrawlings mlrawlings self-assigned this Oct 5, 2017
@patrick-steele-idem
Copy link
Contributor

Earlier discussion can be found in the following GitHub issue: #656

@mlrawlings mlrawlings removed the blocked Cannot be completed before another issue. The blocking issue should be linked. label Jul 4, 2018
@mlrawlings
Copy link
Member Author

Implemented in #1076

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

No branches or pull requests

2 participants