Generating HTML using a template from a .NET application

前端 未结 6 613
后悔当初
后悔当初 2021-01-04 20:35

I have a .NET console application that needs to generate some HTML files. I could just construct the HTML in a StringBuilder and write the contents out to a file, but I was

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 21:29

    Another option instead of using XSLT as Kev suggests is to use named string formatting. Using code like this example by Phil Haack.

    Here you can have your template as a string (read from a file maybe) and format it using the given object.

    Now you could do something like this:

    var person = new { FirstName = "rune", LastName = "grimstad" };
    string template = "

    Hello {FirstName} {LastName}

    "; string html = NamedFormat(template, person);

提交回复
热议问题