Comments (6)
I actually solved my problem for now with a hack of using "import-var": { "children": "arguments[1] }
, but obviously it would be much better if children
existed in the compiled template and was null.
from marko.
It is. I think you are running into a problem because you have an instance of <mytag>
that is not nested within another <mytag>
. This is causing the scoped __children
variable to be undefined and you are seeing an error. I suggest the following:
"import-var": {
"children": "typeof __children === 'undefined' ? null : __children"
}
That should avoid the __children is undefined
error.
from marko.
Ah yeah that makes sense. I've replaced my hack with that and it's working great now. Thanks so much!
from marko.
Glad that worked for you and glad to see that you are taking advantage of these features!
Also, you might want to avoid a generic variable name such as __children
and instead use __mytag
or something that makes it clear where the variable came from and avoids possible variable collisions.
from marko.
Ok cool, I'm still trying to figure out exactly how this all works. I have a little ways to go I think but so far so good. I started looking through the tests and have modified my taglib to use "var": "children"
now and I've removed body-function
in favor of using renderBody(out, {...})
in my renderer. It's working perfectly now. Although I don't feel like I can be completely confident that I'm doing everything correctly because the documentation is a little lacking in this area at the moment, but I'm sure that'll change in the future.
FYI I'm building a simple taglib to render React components and it's actually working great. Maybe I'll publish it on npm if I get some time.
from marko.
Sounds good. You are right that the documentation related to body-function
, renderBody(out)
and import-var
could be improved. The plan is to eventually provide a separate Markdown document that goes into much more depth on building custom taglibs. There's actually a lot of really interesting things you can do at compile time using a custom transformer that manipulates the AST before the code generation phase. In the mean time, if you have any questions on how to accomplish something please ask here or on Gitter.
I would be curious to check out your wrapper around rendering a React component. I do feel like these two technologies do play nice together and welcome any solutions that can bridge the two.
Closing issue now that you have a working solution.
from marko.
Related Issues (20)
- The select element displays the option before the one actually selected HOT 1
- for-loop in script-tag not working HOT 3
- Add styled `console.log` notice in Dev Mode to explain the mutation events warning HOT 2
- [Try Online] - markdown.marko: marked is not a function
- Support optional-chaining in Marko 4
- Why me? HOT 2
- Marko drops closing quote around value HOT 1
- Bug: broken link in CONTRIBUTING.md HOT 1
- bug: no such script in packages.json HOT 1
- try catch not supported when rendering
- error when rendering with $!{} in .marko file HOT 3
- Typescript: add missing directives
- TypeScript: add event handlers like `onclick` to native tags, with type `AttrString`
- TypeScript: Passing Attributes to Body Content Will Loose Type HOT 3
- Webpack error on Marko versions greater than 5.31.0 HOT 5
- Deprecation warnings in Chrome HOT 5
- `onInput` is not running when it is used in `component-browser.ts` HOT 1
- Static functions or arrow functions do not work on components without a class statement
- How does routing work? HOT 2
- Marko not properly tracking dependency updates in some situations when using the tags-api
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marko.