-
Notifications
You must be signed in to change notification settings - Fork 396
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
How to declare additional attribute for a partial? #3419
Comments
You can explicit provide context to the partial instead of wrapping it in a {{>mybutton myvar1}} and after you can use object spread to pass additional attributes: {{>mybutton { ...myvar2, width: 300 } }} I made a working example on Ractive playground. Adding code below for reference: const App = Ractive.extend({
template: `
<h1>Hello</h1>
{{#partial mybutton}}
Partial context:
<pre>{{JSON.stringify(.)}}</pre>
<div>size: {{.size}}</div>
<div>value: {{.value}}</div>
<div>width: {{.width || 'defaultWidthValue'}}</div>
{{/partial}}
{{>mybutton myvar1}}
<hr>
{{>mybutton { ...myvar2, width: 300 } }}
`,
css: `h1 { color: #00818a; }`,
cssId: 'app',
data: () => ({
myvar1: {
size: 10,
value: 't'
},
myvar2: {
size: 15,
value: 't2'
},
}),
});
const app = window.app = new App({
target: 'body'
}); |
@marcalexiei Please show me how you could set the Please do not change this part: {{#partial mybutton}}
<mycomponent size="{{size}}" value="{{value}}"/> <!-- do not add `width="{{width}}"` attribute here -->
{{/partial}} |
To made your example working you have to set Ractive.components["mycomponent"] = Ractive.extend({
isolated: false,
template: `
mycomponent context:
<pre>{{JSON.stringify(.)}}</pre>
<div>size: {{size}}</div>
<div>value: {{value}}</div>
<div>width: {{width}}</div>
`,
data: () => {
return {
size: 5,
value: 3,
}
}
}); I don't like this approach because when debugging it might be not straightforward understand where |
Exactly. I may simply prefer adding |
Is there a known way to declare additional attributes for a partial? For example:
I simply want to use
mycomponent
with some default configuration and then I want to extend it with a new attribute only for the next instance.The text was updated successfully, but these errors were encountered: