MailChimp template variables - c#

So far my site has been using html files on my server. Now I want to utilize Mailchimp and it's template.
This is my html file where I dynamically replace the variables using String's replace in C#.
<h1>
<img src="http://john.doe/test.png" border="0" /></h1>
<hr />
<div style="padding-left: 30px;">
<p>
You have joined John Doe, where you can sell art direct to the public.</p>
<h2>Username and password</h2>
<p>
Here's a reminder of your username and password.</p>
<p>
Username:
<% Email %>
<br />Password:
<% Password %>
</p>
<p>
To log in simply go to
John Doe</p>
<h2>Thanks for joining!</h2>
</div>
So <% Email %> and <% Password %> are dynamically populated. How could I achieve the same in MailChimp template? I visited this page http://templates.mailchimp.com/getting-started/template-language/ but it is not clear how can I achieve this.

Sounds like you want merge tags
For example: instead of <% email %> use *|EMAIL|*
http://kb.mailchimp.com/merge-tags/all-the-merge-tags-cheat-sheet for a list of available merge tags. If you want to send out the password, you probably don't want to use mailchimp at all; you probably want to use Mandrill (from the same company). Also consider SendGrid; or just google 'email api'

Related

Angular js Replace html string with Tokens

I have a Value coming from model that is relatively a huge html String. It also has a token that needs to be replaced with a value from Angular. I am trying to see how to get both of ends meet.
my Html
<h2 class="sub-title"> #Model.WelcomeText </h2>
Now this Welcome text is a relatively a html string that has a token. Something like this
"Hi ##Name , Welcome to our Website. Click <a href='#'> here </a>
for more details. <small> For more details please visit blah blah
</small>
Now i need to replace ##Name with a model value in my controller- $scope.Name
I tried
<h2 class="sub-title" ng-init= $scope.welcomeText('#Model.WelcomeText') </h2>
and then in my controller
function welcomeText(str)
{
return str.replace('##Name',$scope.Name);
}
But it breaks in the html itself because of $scope.welcomeText has invalid values inside ng-init
Any pointers on how to achieve this? The Model.Title is from a Sitecore CMS. I dont have that value in JS
I ended up doing this. Not sure if this is the ideal solution but atleast it works.
//Added a div with hidden class to get the value.
<div class="hidden" id="inp-title-server" /> #Model.Title </div>
<h2 class="sub-title" data-ng-bind-html="$scope.header"></h2>
Then in my controller,
var title = $("#inp-title-server").text();
$scope.header = title.replace('##Name', $scope.Name);
You can simply use replace function of string.
angular.module("app",[])
.controller("ctrl",['$scope',function($scope){
$scope.WelcomeText = "Hi ##Name , Welcome to our Website. Click <a href='#'> here </a> for more details. <small> For more details please visit blah blah </small>";
$scope.UserName = "ABC";
$scope.WelcomeText = $scope.WelcomeText.replace("##Name",$scope.UserName);
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<body ng-app="app" ng-controller="ctrl">
<h4 class="sub-title" ng-bind="WelcomeText"> </h4>
</body>
<html>

How to provide unique element IDs for items generated by a Repeater?

I am using Repeater in ASP.Net. I am accessing content from the data base. Every id or class of html element is same. It is a new heading in multiple. There is read button.
I want to open a new page with full description of that heading in a new page.
I have problem in assigning unique id from which I know which heading is clicked.
This is the code of that part:
<div class="content">
<table>
<tr>
<td class="contl">
<div>
<asp:Repeater ID="RepCountry" runat="server" OnItemCommand="RepCountry_ItemCommand">
<ItemTemplate>
<div class="contentbox">
<div class="postheading">
<%#Eval("title")%>
</div>
<table>
<tr><td> <div class="postimage">
<img src="Admin/images/<%# Eval("img")%>" alt="" height="50%" width="100%" />
</div></td>
<td><div class="discp">
<div class="dpost">
<p style="font-family: Times New Roman">
<%#Eval("p_date")%></p>
</div>
<div class="discp_c">
<p>
<%# Eval("descr").ToString().Substring(0,200).ToString()%></p>
<p style="color: Maroon">
<a id="A1"+ href="Readmore.aspx?oid=" runat="server" onclick="changeid(this.id)">Read More.</a></p>
</div>
<div class="social">
<a href="">
<img src="images/t.png" alt="twtter" /></a> <a href="">
<img src="images/f.png" alt="facebook" /></a> <a href="">
<img src="images/g.png" alt="gmail" /></a> <a href="">
<img src="images/in.png" alt="linkedin" /></a>
</div>
</div></td></tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
I see you have already used Eval to insert a Description in your items:
<div class="discp_c">
<p>
<%# Eval("descr").ToString().Substring(0,200).ToString()%></p>
<p style="color: Maroon">
...
If I read the code well, you are reading at least title, descr, img the database query?
If so, then make sure that the query also returns the ID (Primary Key) of the article, and use Eval to insert that ID in the link. So, if the primary key of the article in the database is named for example articleID, then change your database query from
SELECT xxx as title, yyy as descr, zzz as img ....
to
SELECT id as articleID, xxx as title, yyy as descr, zzz as img ....
Then you can use the ID provided by the database to make a full link to an article:
<a runat='server' ....
href='Readmore.aspx?oid=<%# Eval("articleID").ToString()%>'
....>
...</a>
and so the Readmore.aspx page will exactly know which article should be opened. It will come directly as oid query parameter, no extra work to do.
If you really need it, you can use the same trick to generate the HTML ID of that tag:
<a runat='server' ....
id='ID_<%# Eval("articleID").ToString()%>'
href='Readmore.aspx?oid=........'
....>
...</a>
and with that, the <a> tags will have IDs like ID_32131, ID_4532455, ID_1231455 and the IDs will be unique as long as the database query returns unique articles.

How can I Insert an Umbraco Item in to a url in a cshtml file, razor?

I've made an If statement containing a youtube link.
In umbraco I have a Text String box that enables a user to insert the ID of a youtube video.
<div class="module m-video">
<div class="regular">
<div class="graphics video-container">
<iframe width="100%" src="http://www.youtube.com/embed/<umbraco:Item field="youtubeId" runat="server" />?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
But when the page loads it displays the <umbraco:Item field="youtubeId" runat="server" /> instead of what the user put in.
What work around is their to display what a user inserts into the text string box.
All must be done in razor
I would create a "YoutubeVideo" macro along with it's razor script "YoutubeVideo.cshtml". And that cshtml code would look like this:
#using umbraco.MacroEngines
#inherits umbraco.MacroEngines.DynamicNodeContext
<div class="module m-video">
<div class="regular">
<div class="graphics video-container">
<iframe width="100%" src="http://www.youtube.com/embed/#Model.youtubeId?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
Then in your .master you could include that mascroscript like this:
<umbraco:Macro ID="Macro1" Alias="YoutubeVideo" runat="server" />
This approach may differ if you are using Umbraco 6+ with MVC, but otherwise this should do the trick.
If you are doing this inside the umbraco template editor you should be able to swap the double quotes denoting the src attribute with single quotation marks, and the umbraco item needs no change.
<iframe width="100%" src='http://www.youtube.com/embed/<umbraco:Item field="youtubeId" runat="server" />?rel=0' frameborder="0" allowfullscreen></iframe>

Using xval to client side validate forms

I am using ASP.NET MVC2 and to validate the forms i use xVal. It seems like the server side validation works fine, but the client side validation doesnt work or atleast doesn't show up.
The code i use looks like this:
<% using (Html.BeginForm()) {%>
div class="label"><label for="EmailAddress">Email Address</label></div>
<div class="field">
<%= Html.TextBox(Prefix + ".EmailAddress")%>
<%= Html.ValidationMessage(Prefix + ".EmailAddress")%>
</div>
<%}%>
<%= Html.ClientSideValidation<Customer>(Prefix)%>
When i remove the prefix it works fine. But when i remove it only the server side validation works.
Searching on xVal on this side i found this post that looks a bit like the same problem:
Using xval with fields containing periods
But no answers here (yet).
Thanks in advance for the help.
Solved it with the following code:
<% using (Html.BeginForm("ActionName", "Controller")) {%>
div class="label"><label for="EmailAddress">Email Address</label></div>
<div class="field">
<%= Html.TextBox("EmailAddress")%>
<%= Html.ValidationMessage("EmailAddress")%>
</div>
<%}%>
<%= Html.ClientSideValidation<Customer>()%>

Uploading an image in ASP.NET MVC using EDM

I am new to using ASP.NET MVC and I've been having some difficulties with it. I created my model using the Entity Data Model just for the record.
My problem is that I'm trying to insert an image into my MS SQL 2008 server using my new ASP.NET page. The image is a part of the information that I need to store about Employees in my database. From my home HomeController.cs file I right-clicked the Create method and chose to create a view, which it did. However, uploading an image was not part of the auto-generated code.
In the Create View there are a few text-boxes that correspond to my table columns and a single submit button that creates my new database row somehow. I thought that the button would run the code for the other Create method in the HomeController.cs file that takes an Employee as a parameter but I guess my problem lies in the fact that I don't know what happens between me pressing the Submit button and the creation of an Employee object for the Create method.
For reference, here is the code I'm working with .First code for Homecontroller.cs and then code for Create.aspx (note that the variable _db is a copy of my Entity Data Model):
public ActionResult Create()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "employeeNumber")] Employee employeeToCreate)
{
try
{
_db.AddToEmployee(employeeToCreate);
_db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
I don't know why the code above indent's the way it does.
I also don't know why, but the code below doesn't show the first few lines properly so I deleted a few < > around C# code and asp code in order for the code to become visible.(FIXED)
<Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<LaunakerfiASP_MVC.Models.Employee>"
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Create</h2>
<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) { %>
<fieldset>
<legend>Fields</legend>
<p>
<label for="name">name:</label>
<%= Html.TextBox("name")%>
<%= Html.ValidationMessage("name", "*")%>
</p>
<p>
<label for="email">email:</label>
<%= Html.TextBox("email")%>
<%= Html.ValidationMessage("email", "*")%>
</p>
<p>
<label for="department">department:</label>
<%= Html.TextBox("department")%>
<%= Html.ValidationMessage("department", "*")%>
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%=Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
So what I would like to do is to add an element to the Create.aspx view that let's me upload an image to the column 'picture' in the table 'Employee'.
In your controller action, you can access the uploaded files through Request.Files
Here are some links about file uploads in ASP.NET MVC :
http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx
http://aspzone.com/tech/asp-net-mvc-file-upload/

Categories