Giter Club home page Giter Club logo

Comments (5)

carlreinke avatar carlreinke commented on July 24, 2024 1

I'm trying to generate URLs from routes (either using the built-in anchor tag helper or using a custom tag helper). Right now I have href="@(SomeUrlHelper.GetWhateverUrl(_context, someId))", but I think I'd rather have asp-route="whatever" asp-route-id="@someId" and not have to write URL a generator method for every route.

So I can certainly live without tag helpers, it just seemed like it might be convenient.

If tag helpers aren't going to be supported, it would be nice to produce an error from the generator if the template contains an @addTagHelper directive. The Razor compiler is pretty modular, but it looks like the @addTagHelper is built-in and can't be disabled. Maybe there's a way to examine the Razor syntax tree and produce a diagnostic on the directive syntax node or replace the IRazorTagHelperBinderPhase with one that produces a diagnostic?

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on July 24, 2024

Tag helpers are currently not implemented in RazorBlade.

To be honest I'm not sure I want to add them, as this library is meant to be lightweight. It's supposed to generate simple HTML output, not fully-fledged pages which communicate with a server. I don't really want to reimplement ASP.NET. 🙂

Also, I expect the IDE support for them to be poor (it wouldn't recognize the special tags, it would just treat them as regular markup).

In some cases, you can get a similar result by composing your templates: @(new SomeOtherTemplate(AndItsArgument)) or by using any other object which implements IEncodedContent instead.

If this is insufficient, could you tell me what you're trying to do, so I can see how tag helpers would help?

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on July 24, 2024

Ok, I see. I think I'll play with them in the future to see how it goes.

I didn't notice that @addTagHelper was currently accepted by the parser. Thanks for the info, I'll definitely add an error if I end up not adding tag helper support.

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on July 24, 2024

I ended up adding an error when trying to use tag helpers.

I tried to add support for them in the tag-helpers branch, but realized it would go off the rails.

I wanted to integrate the Microsoft.AspNetCore.Razor.Runtime package (which implements tag helpers without depending on a lot of ASP.NET stuff) with RazorBlade: the idea was that you'd get tag helper support if you reference that package. Unfortunately, Microsoft deprecated it after I started implementing the feature. 🙄

So that's a dead end - it seems the tag helpers implementation will be shipped in the SDK, and not available as a nicely self-contained external NuGet package that I could use.

Also, integrating the Razor runtime package wouldn't be seamless, since it would import stuff that RazorBlade implements on its own, and you wouldn't necessarily know which feature should be used in a given context.

Maybe someday I could revisit this, but it's best to keep things simple for now I guess.

from razorblade.

carlreinke avatar carlreinke commented on July 24, 2024

Thanks for trying to make it work anyway!

from razorblade.

Related Issues (11)

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.