GithubHelp home page GithubHelp logo

Self-nested taglibs about marko HOT 6 CLOSED

marko-js avatar marko-js commented on May 7, 2024
Self-nested taglibs

from marko.

Comments (6)

dizlexik avatar dizlexik commented on May 7, 2024

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.

patrick-steele-idem avatar patrick-steele-idem commented on May 7, 2024

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.

dizlexik avatar dizlexik commented on May 7, 2024

Ah yeah that makes sense. I've replaced my hack with that and it's working great now. Thanks so much!

from marko.

patrick-steele-idem avatar patrick-steele-idem commented on May 7, 2024

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.

dizlexik avatar dizlexik commented on May 7, 2024

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.

patrick-steele-idem avatar patrick-steele-idem commented on May 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.