Last active
August 29, 2015 14:04
-
-
Save mahmut-gundogdu/e6705a7bb85b854ef9db to your computer and use it in GitHub Desktop.
Dotliquid ile temiz ve kolay mail template olusturma - Yazi:http://mahmutgundogdu.azurewebsites.net/?p=230
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Bu kodlar ile txt dosyasından aldık. Böylece Taslak Değişeceği zaman template.html değiştirmek yeterli. | |
TextReader txt = File.OpenText(Server.MapPath("~/App_Data/template.html")); | |
var strTemplate=txt.ReadToEnd(); | |
txt.Close(); | |
txt.Dispose(); | |
//Adim 1. Templatei verdik. | |
Template template = Template.Parse(strTemplate); | |
//Veri Normalde bu database den gelir ben kendim olusturdum. | |
var data = new kullanici() | |
{ | |
adsoyad = "Mahmut Gündoğdu", | |
siparisler = new List<siparis>() { | |
new siparis() {aciklama="Sipariş 1",tarih=DateTime.Now.AddDays(1),tutar=100}, | |
new siparis() {aciklama="Sipariş 2",tarih=DateTime.Now.AddDays(2),tutar=200}, | |
new siparis() {aciklama="Sipariş 3",tarih=DateTime.Now.AddDays(3),tutar=300}, | |
new siparis() {aciklama="Sipariş 4",tarih=DateTime.Now.AddDays(4),tutar=400}, | |
new siparis() {aciklama="Sipariş 5",tarih=DateTime.Now.AddDays(5),tutar=500} | |
} | |
}; | |
//Adim 2. Verileri verdik. Sonucu Aldık | |
var sonuc = template.Render(Hash.FromAnonymousObject(data)); | |
this.ltr.Text = sonuc; | |
MailGonder(sonuc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DotLiquid; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
/// <summary> | |
/// Summary description for kullanici | |
/// </summary> | |
public class kullanici | |
{ | |
public string adsoyad { get; set; } | |
public List<siparis> siparisler { get; set; } | |
} | |
/// <summary> | |
/// burda DROP dan inherit etmezsek dotliquid hata veriyor | |
/// </summary> | |
public class siparis:Drop | |
{ | |
public string aciklama { get; set; } | |
public DateTime tarih { get; set; } | |
public double tutar { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Sayın {{ adsoyad }} mağazamızdan yaptığınız son 5 işleminiz:</p> | |
{{ siparisler.Count}} | |
<ul> | |
{% for item in siparisler -%} | |
<li>{{ item.aciklama }} - {{ item.tarih }} - {{ item.tutar }}</li> | |
{% endfor -%} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment