Comments (5)
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.
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.
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.
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.
Thanks for trying to make it work anyway!
from razorblade.
Related Issues (11)
- `CancellationToken` in templates HOT 3
- Make the generator self-contained (no runtime dependency) HOT 9
- Can't use template with a model when RazorBladeEmbeddedLibrary is true HOT 4
- DiagnosticId is not available in netstandard2.0 HOT 2
- Layout support HOT 4
- Cannot use RazorBlade in a roslyn SourceGenerator, because it requires C# 10, and source generators need to target netstandard2.0 which only has c# 7.3 HOT 2
- Forward base class constructors by default HOT 16
- When trying the example with a model, I get a template generated which do not accept a model arg in the ctor ? HOT 1
- Streaming HTML HOT 2
- Getting IDE error HOT 11
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 razorblade.