question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Add ZML Views and ZML Pages

See original GitHub issue

Proposal:

I suggest to support a new ZML views / pages with the file extension .zml. ZML stands for raZor XML, where I represented language statements as XML tags.

Benefits:

This can achieve the following:

  1. Using a more homogeneous code, which is just an XML code!
  2. Using less { } ; @ symbols, so, the code will be more compact and more friendly.
  3. Using one generalized view syntax makes it valid for use for all programming languages.
  4. This will eliminate the need to create vbxml and fshtml razor views!
  5. All Razor rules still applies, so the learning curve is low.
  6. Building ZML views on the top of Razor engine means it will benefit from any future new features added to the Razor engine, which uses C# as the internal language.
  7. Pages designed in apps written by any language, can be reused in other languages as they are!

The cost to implement ZML in .NET is the cost of witting an easy ZML tags to C# translator and add VS.NET editor support for ZML files.

#Implementation: I add a ZML support in Vazor. I translate ZML tags to C# code to get a C# Razor, then send it to Razor engine to carry the work! This ZML Module contains a simple implementation of ZML using XML literals in VB.NET. It doesn’t do any syntax check, assuming the ZML format is reviewed by the editor. Currently, it supports:

  • <page/> for @page

  • <model type="mtype" /> for @model mtype Note: if the type is generic, use VB syntax <model type="List(Of mtype)" />, because XML literals considers List<mtype> as an opining tag without the closing one!

  • <set object="obj" value="val"/> for C# Razor:

@{
    obj = val;
}
  • ZML tag:
<if  condition="cond">
    block of zml code
</if>

for C# Razor:

@if  (cond)
{
    block of zml code
}
  • ZML tag:
<if  condition="cond1">
  <then>
    block of zml code
  </then>
  <elseif condition="cond2">
    block of zml code
  </elseif>
  <!--repeate elseif tags as you need -->
  <else>
    block of zml code
  </else>
</if>

for C# Razor:

@if  (cond1)
{
    block of zml code
 }
 elseif (cond2)
{
    block of zml code
}
else
{
    block of zml code
}

Note: you can nest if tags as you need.

  • ZML tag:
<foreach var="m" in="Model">
    block of zml code
</foreach>

for C# Razor:

@foreach (var m in Model)
{
    block of zml code
}

These are the supported ZML tags until now (which are the most used), but every language structure can be represented in the same way.

Example:

ZML code:

<page />
<model type="CatalogModel"/>
 
<set object="ViewData["Title"]" value="zml sample" />
<set object="ViewData("Message")" value="another syntax" />

<div class="container">
       <if  condition="CatalogModel.CatalogItems.Any()">
          <then>
             <partial name="_pagination" for="CatalogModel.PaginationInfo"/>
                   <div class="esh-catalog-items row">
                       <foreach   var="catalog" in="CatalogItems">
                            <div class="esh-catalog-item col-md-4">
                                <partial name="_product" for="@catalog" />
                            </div>
                       </foreach>
                 </div>
              <partial name="_pagination" for="CatalogModel.PaginationInfo"/>
          </then>
          <elseif condition="X>3">
                <!--we can have elseif too-->
          </elseif>
          <else>
              <div class="esh-catalog-items row">
                     THERE ARE NO RESULTS THAT MATCH YOUR SEARCH
              </div>
         </else>
     </if>
</div>

Which can is translated to this C# Razor:

@page 
@model CatalogModel

@{
     ViewData["Title"] = "zml sample";
     ViewData["Message"] = "another syntax";
}

<div class="container">
       @if  (@Model.CatalogModel.CatalogItems.Any())
          {
             <partial name="_pagination" for="CatalogModel.PaginationInfo"/>
                   <div class="esh-catalog-items row">
                       @foreach (var catalog in @Model.CatalogItems)
                        {
                            <div class="esh-catalog-item col-md-4">
                                <partial name="_product" for="@catalog" />
                            </div>
                        }
                 </div>
              <partial name="_pagination" for="@Model.CatalogModel.PaginationInfo"/>
          }
          elseif (X>3)
          {
                <!--we can have elseif too-->
          }
          else
          {
              <div class="esh-catalog-items row">
                     THERE ARE NO RESULTS THAT MATCH YOUR SEARCH
              </div>
         }
</div>

Vazor contains a working simple sample, the index.vbxml.vb file contains this ZML block

  <ul>
      <foreach var="m" in="Model">
           <li>
                Id: @m.Id<br/>
                Name: @m.Name<br/>
                <p>Grade: @m.Grade</p>
           </li>
      </foreach>
  </ul>

Which generates this C# Razor:

<ul>
   @foreach (var m in Model)
   {
     <li>
        Id :  @m.Id<br />
        Name: @m.Name<br />
        <p>Grade: @m.Grade</p>
    </li>
   }
</ul>

Note:

I can’t create ZML editor myself. It is easier for you to modify the Razor editor to deal with ZML tags. If this to happen, I expect there will be no need to use the @ inside the ZML attributes, nor the Model keyword in most cases. The editor can also allow the use of <T> for generics. I advise to allow using (Of T) or <T>, and ((i) or [i] notations, to let VB and C# developers write the syntax they are familiar with.

Conclusion:

ZML is an easy to write, read and learn code, because it is an XML code but very close to C# and VB.NET code. It can add a great value to VS.NET with low cost, and will give VB.NET and F# developers the ability to design web pages with homogeneous XML code. C# programmers also can find this ZML views attractive.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Eiloncommented, Apr 11, 2019

Hi, we are closing this issue because there are no plans to add additional view engines to ASP.NET Core at this time.

We encourage you to work on this as a community project.

0reactions
VBAndCscommented, Apr 25, 2019

ZML 1.0 now has its own repo and NuGet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a ZML Snippet to a Page
Adding an ZML snippet to your page​​ Edit your app. Navigate to the Design tab and open the page builder. In the page...
Read more >
Process configuration XML elements - Azure DevOps
XML syntax and usage for all ProcessConfiguration elements to support customization of work item types and Agile tool backlogs and boards.
Read more >
Build a responsive UI with ConstraintLayout
To define a view's position in ConstraintLayout , you add at least one horizontal and ... click the module folder and select File...
Read more >
Using a view to generate XML
For views displaying XML, the page contains the XML declaration and root ... Click "View Selection" on the Objects tab and add a...
Read more >
XML Sitemaps Feature Project Proposal - Make WordPress
This post proposes integration of XML Sitemaps to WordPress Core as a feature project. The proposal was created as a collaboration between ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found