Skip to content

[Blazor] @if directive #9243

@mrpmorris

Description

@mrpmorris

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I'd like to be able to create markup that is nice to look at and easy for a non-programming colleague to improve the visual design of.

@if (IWantToWriteNiceCode)
{
  <ThisDoesntFloatMyBoat/>
}

This isn't nice to look at, it's quite verbose, and my non-programming colleague would undoubtedly break the logic when changing the contents to make them look good.

Describe the solution you'd like

I'd like to be able to have if and foreach directives, so my colleague only needs to know not to change any html attributes that start with an @ symbol (as is already the case).

<ThisDoesFloatMyBoat @if=IWantToWriteNiceCode/>

The preceding code is much nicer to look at, quicker to type, uses only a single line so uses less space, and easy to see what can be moved/altered without breaking things.

I would also like to be able to replace the following

@foreach(var person in People)
{
  <li>@person.Name</li>
}

With something more simple such as

 <li @foreach-person="People">@person.Name</li>

I resist giving judgement on a switch statement :)

Additional context

https://i.ibb.co/8gsnjg7/Fm68-Ngz-Xw-AA8xqv.png

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions