1

I've a question related to dynamic code generation (html) with C# based on a template. The user sets all options (e.g. whether or not a <div> should be displayed, whether or not an image in the template should change by a specific date,...) and provides the content (text, images) needed for code generation. The generated code is needed for a WIFI hotspot site.

The template consists of HTML, CSS and JavaScript which gets extended and modified by the user-defined settings at runtime. I also think of providing "meta settings" in the template to define, whether or not some options CAN be disabled set or not.

My major problem:

How to define the template to dynamically extend the template code easily? For example, if a user option is enabled at runtime, I'm in need to add JavaScript code on top and HTML code below another (specific) place. Another example is to hide content (a defined ) when another option is disabled...

I'm not sure what's the best practice to handle that requirement. Maybe HTML elements with id attribute can help eliminate some of the problems. But with JavaScript I'm not sure. Maybe the template needs to be a XML which creates the final HTML at runtime? Any idea?

Has anyone an idea how to handle that?

UPDATE/INFO:

The project is written in pure C# - without any ASP.NET. It is a desktop project working with HTML files and GENERATING HTML files (as an output).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
thedom
  • 2,498
  • 20
  • 26
  • I'd fetch DotNetNuke and start from that, at least you'll have a complete CMS structure (which you basically are after, and would need a truckload of time and effort to achieve) – Alex Apr 04 '13 at 11:55
  • The project is written in plain c# - without asp. Only the template is in html and the c# code should generate a html file too. But it isn't a web but a desktop project. – thedom Apr 04 '13 at 12:05

1 Answers1

1

I suppose you can use ASP.NET MVC Razor view engine to render an html to a file with the help of this question. With Razor you will get the support of dynamic view (aka template) changes, rich template syntax etc. Everything you can do when create a web site. Just render the html to a file not a response body.

Community
  • 1
  • 1
lavrik
  • 1,456
  • 14
  • 25
  • The code is written in c#. I'm only generating and operating with html code. The c# project itself is for desktop users. – thedom Apr 04 '13 at 12:10
  • Ok. I don't thinks it's a big problem. You can use the view engine only from the asp mvc. Just some mocking for http context but the same as if you write tests. Also you can try NVelocity. It's also a good thing i use to generate html-based emails in some projects. – lavrik Apr 04 '13 at 16:11