I have home text page,some thing like this
Welcome to our store..... that is for user not login
If some one login the text should be
Welcome {FirstName} to our store.Where:{FirstName} is FirstName of user login
Any idea for this?
Thanks
@using Nop.Core
@using Nop.Core.Domain.Customers
@using Nop.Core.Infrastructure
@Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
@{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
if (workContext.CurrentCustomer.IsGuest())
{
@Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
}
else
{
@Html.Raw(string.Format("<h2>Hello, {0}</h2>", workContext.CurrentCustomer.Username ?? workContext.CurrentCustomer.Email))
}
}
@{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var user = string.Empty;
if (!workContext.CurrentCustomer.IsGuest())
{
user = workContext.CurrentCustomer.Username ?? workContext.CurrentCustomer.Email;
user = user + ", ";
}
@Html.Raw(string.Format("<h2>Welcome {0}to our store</h2>", user))
@Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
}
@model TopicModel
@using Nop.Core
@using Nop.Web.Models.Topics
@using Nop.Core.Infrastructure
@using Nop.Core.Domain.Customers
@{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var currentCustomer = workContext.CurrentCustomer;
var displayName = "guest";
if (!currentCustomer.IsGuest())
{
displayName = currentCustomer.Username ?? currentCustomer.Email;
}
}
@helper RenderTextWithUserToken(string rawText, string user) {
@Html.Raw(rawText.Replace("{logged-user}", user))
}
@if (Model.IsPasswordProtected)
{
<script type="text/javascript">
$(function () {
$('#[email protected]').click(function () {
var topicId = $("#@Html.FieldIdFor(model => model.Id)").val();
var password = $('#[email protected]').val();
$.ajax({
cache: false,
type: 'POST',
url: '@Url.RouteUrl("TopicAuthenticate")',
data: { "id": topicId, "password": password },
dataType: 'json',
success: function (data) {
if (data.Authenticated) {
$('#[email protected] .topic-html-content-title h2.topic-html-content-header').html(data.Title);
if ($('#[email protected] .topic-html-content-title h2.topic-html-content-header').text().length == 0) {
$('#[email protected]').hide();
}
$('#[email protected] .topic-html-content-body').html(data.Body);
$('#[email protected]').hide();
$('#[email protected]').show();
}
else {
$('#[email protected]').text(data.Error);
$('#[email protected] #[email protected]').select().focus();
}
}
});
return false;
});
});
$(document).ready(function () {
$('#[email protected]').hide();
$('#[email protected] #[email protected]').select().focus();
});
</script>
<div class="topic-password" id="[email protected]">
@using (Html.BeginRouteForm("TopicAuthenticate"))
{
@Html.HiddenFor(model => model.Id)
<div class="enter-password-title">
@T("Topic.EnterPassword")
</div>
<div class="enter-password-form">
@Html.Password("password", null, new { id = "password-" + @Model.Id })
<input type="submit" id="[email protected]" value="@T("Topic.Button")" class="button-1 topic-password-button" />
</div>
<div class="password-error">
<span id="[email protected]"></span>
</div>
}
</div>
<div class="topic-html-content" id="[email protected]">
<div id="[email protected]">
<div class="topic-html-content-title">
<h2 class="topic-html-content-header">
@RenderTextWithUserToken(Model.Title, displayName)
</h2>
</div>
</div>
<div class="topic-html-content-body">
@RenderTextWithUserToken(Model.Body, displayName)
</div>
</div>
}
else
{
<div class="topic-html-content">
@if (!String.IsNullOrEmpty(Model.Title))
{
<div class="topic-html-content-title">
<h2 class="topic-html-content-header">
@RenderTextWithUserToken(Model.Title, displayName)
</h2>
</div>
}
<div class="topic-html-content-body">
@RenderTextWithUserToken(Model.Body, displayName)
</div>
</div>
}
@model TopicModel
@using Nop.Core
@using Nop.Web.Models.Topics
@using Nop.Core.Infrastructure
@using Nop.Core.Domain.Customers
@{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var currentCustomer = workContext.CurrentCustomer;
var displayName = "guest";
if (!currentCustomer.IsGuest())
{
displayName = currentCustomer.Username ?? currentCustomer.Email;
}
}
@helper RenderTextWithUserToken(string rawText, string user) {
@Html.Raw(rawText.Replace("{logged-user}", user))
}
@if (Model.IsPasswordProtected)
{
<script type="text/javascript">
$(function () {
$('#[email protected]').click(function () {
var topicId = $("#@Html.FieldIdFor(model => model.Id)").val();
var password = $('#[email protected]').val();
$.ajax({
cache: false,
type: 'POST',
url: '@Url.RouteUrl("TopicAuthenticate")',
data: { "id": topicId, "password": password },
dataType: 'json',
success: function (data) {
if (data.Authenticated) {
$('#[email protected] .topic-html-content-title h2.topic-html-content-header').html(data.Title);
if ($('#[email protected] .topic-html-content-title h2.topic-html-content-header').text().length == 0) {
$('#[email protected]').hide();
}
$('#[email protected] .topic-html-content-body').html(data.Body);
$('#[email protected]').hide();
$('#[email protected]').show();
}
else {
$('#[email protected]').text(data.Error);
$('#[email protected] #[email protected]').select().focus();
}
}
});
return false;
});
});
$(document).ready(function () {
$('#[email protected]').hide();
$('#[email protected] #[email protected]').select().focus();
});
</script>
<div class="topic-password" id="[email protected]">
@using (Html.BeginRouteForm("TopicAuthenticate"))
{
@Html.HiddenFor(model => model.Id)
<div class="enter-password-title">
@T("Topic.EnterPassword")
</div>
<div class="enter-password-form">
@Html.Password("password", null, new { id = "password-" + @Model.Id })
<input type="submit" id="[email protected]" value="@T("Topic.Button")" class="button-1 topic-password-button" />
</div>
<div class="password-error">
<span id="[email protected]"></span>
</div>
}
</div>
<div class="topic-html-content" id="[email protected]">
<div id="[email protected]">
<div class="topic-html-content-title">
<h2 class="topic-html-content-header">
@RenderTextWithUserToken(Model.Title, displayName)
</h2>
</div>
</div>
<div class="topic-html-content-body">
@RenderTextWithUserToken(Model.Body, displayName)
</div>
</div>
}
else
{
<div class="topic-html-content">
@if (!String.IsNullOrEmpty(Model.Title))
{
<div class="topic-html-content-title">
<h2 class="topic-html-content-header">
@RenderTextWithUserToken(Model.Title, displayName)
</h2>
</div>
}
<div class="topic-html-content-body">
@RenderTextWithUserToken(Model.Body, displayName)
</div>
</div>
}
@model IList<string>
@using Nop.Core
@using Nop.Core.Domain.Customers
@using Nop.Core.Infrastructure
@using Nop.Services.Localization
@{
var engineContext = EngineContext.Current;
var workContext = engineContext.Resolve<IWorkContext>();
var localizationService = engineContext.Resolve<ILocalizationService>();
var currentCustomer = workContext.CurrentCustomer;
var textForGuest = Model[0];
var textForLoggedUser = Model[1];
var displayName = localizationService.GetResource("customer.guest");
var isGuest = currentCustomer.IsGuest();
if (!isGuest)
{
displayName = currentCustomer.Username ?? currentCustomer.Email;
}
}
@helper RenderTextWithUserToken(MvcHtmlString htmlString, string user)
{
@Html.Raw(htmlString.ToString().Replace("{logged-user}", user))
}
@RenderTextWithUserToken(Html.Action("TopicBlock", "Topic", new { systemName = isGuest ? textForGuest : textForLoggedUser }), displayName)
@Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
@Html.Partial("_TopicBlockWithCustomTokens", new List<string>() { "HomePageTextForGuest", "HomePageTextForLoggedUser" })