How to implement D to HTML pages ?
bauss
jj_1337 at live.dk
Wed Oct 3 05:01:26 UTC 2018
On Tuesday, 2 October 2018 at 18:27:04 UTC, Aurélien Plazzotta
wrote:
> On Tuesday, 2 October 2018 at 06:56:33 UTC, bauss wrote:
>> On Monday, 1 October 2018 at 23:17:59 UTC, rjframe wrote:
>>>
>>> vibe.d has more of a node.js feel. There's also
>>> DiamondMVC[1], which reminds me of ASP.NET (I'm not 100% sure
>>> whether that's intentional, and I haven't tried Diamond) and
>>> includes an ORM.
>>
>> As the creator of Diamond, then I can say it's 100%
>> intentional that it reminds of ASP.NET. It was originally just
>> an alternative template engine to vibe.d to create views
>> similar to razor, but now it's a full-stack web-framework
>> specifically targeting enterprise development, hence why the
>> similarities to ASP.NET.
>>
>> As described on the website (https://diamondmvvc.org/):
>>
>> "Diamond is build on modern principles using vibe.d, inspired
>> by ASP.NET and razor templates."
>>
>> It can also be used in combination with vibe.d projects, in
>> which you can just utilize the extra tools Diamond gives you
>> such as some additional security, authentication, api
>> creation, database management (ORM) etc.
>
> Thank you both for all the links! I guess DiamondMVC is very
> powerful but I would rather avoid using such heavy artillery.
> I'm expecting the learning curve to be very long.
>
> Do you know of template engines in D ? like Jinja2 in Python
> for example. It would be way more lightweight and
> free-dependancies compared to a fully featured framework like
> DiamondMVC, besides the gain in time thanks to the simplicity
> of use.
The learning curve is actually not that long since it's a
relative small setup. It's a heavy beast, BUT everything is
pretty much optional and opt-in, so you really only just use what
you need.
So for templating, just setup a project, the configuration and
then create views.
As soon as you're familiar with the template syntax then you're
good to go without knowing the whole framework etc.
You can write templates using D in it.
Simple example: After 3.0.0 which is coming soon then @<> is
replaced by @()
layout.dd:
```
@<doctype>
<html>
<head>
<title>Website - @<title></title>
</head>
<body>
@<view>
</body>
</html>
```
home.dd:
Notes: placeholders is equivalent to an associative array in D.
```
@[
route:
home
---
placeholders:
[
"title": "Home"
]
]
<p>Hello World!</p>
```
Output:
```
<!DOCTYPE html>
<html>
<head>
<title>Website - Home</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
```
It's pretty much plug and play too using this as an empty example
project:
https://diamondmvc.org/download
See empty project.
It'll be ready to just compile and run.
After that you can just work with views if you just want to use
simple templates. No need to know the whole framework or any long
installation guides.
More information about the Digitalmars-d-learn
mailing list