-
-
Notifications
You must be signed in to change notification settings - Fork 18
Script locals always override the locals passed via attribute #132
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
Comments
@thewebartisan7 I just stumbled with this situation today! I sent a PR to address this situation, allowing using global locals from config or even when using Would you like to test if my chance solves your issue as well?
or if case you use
"overrides": {
"posthtml-include": {
"posthtml-expressions": "github:Konnng/posthtml-expressions"
}
} or "resolutions": {
"**/posthtml-expressions": "github:Konnng/posthtml-expressions"
}
With my forked package, you would just need to change to: <script locals>
module.exports = {
name: locals.name ? locals.name : "John"
}
</script> Hope it helps 👍🏻 |
Thanks! Will try for sure At the moment I am doing something like below, but with your solution it's much cleaner <script locals>
module.exports = {
defaultName: "John"
}
</script>
<span>
{{ typeof name !== "undefined" ? name : defaultName }}
</span> |
Works perfectly! I tested with posthtml-include, posthtml-extend and posthtml-modules and works perfectly with all of them! <!-- test/test-local.html -->
<script locals>
module.exports = {
...{
text: "Default text",
text2: "Default text2",
text3: "Default text3",
},
...locals
}
</script>
<span>
text is {{ text }}<br>
text2 is {{ text2 }}<br>
text3 is {{ text3 }}<br>
</span> <!-- test/test-page.html -->
<include src="test/test-local.html"></include>
<include src="test/test-local.html" locals='{ "text": "I am set via attribute locals" }'></include>
<module href="test/test-local.html" locals='{ "text": "I am set via attribute locals" }'></module>
<module href="test/test-local.html" text='I am set via attribute value-name'></module> <!-- test/layout.html -->
<script locals>
module.exports = {
...{
bodyClass: "body-class",
title: "title"
},
...locals
}
</script>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
page title: {{ title }}<br>
body class: {{ bodyClass }}
<div class="content">
<block name="content"></block>
</div>
<footer>
<block name="footer">footer content</block>
</footer>
</body>
</html> <!-- test/test-layout.html -->
<extends src="test/layout.html" locals='{ "bodyClass": "new body class" }'>
<block name="title">How to use posthtml-extend</block>
<block name="content">Read the documentation</block>
</extends> This is great addition as right now I was using always typeof check before using variable, and this way looks pretty similar to Blade default props! I hope your PR get merged soon! |
@thewebartisan7 I'm glad that my change solved your issue and thanks for testing even further! Friendly ping to @Scrum |
v1.10.0 |
Would be possible that script locals inside component act as default locals, and the locals passed via attribute override the script locals?
Because right now it's the opposite, the script locals override the locals passed via attribute.
And I can't even do something like this:
When "name" is the locals passed via attribute locals.
The text was updated successfully, but these errors were encountered: