Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi Guys,
just trying to do the following I have a cshtml page called PageTitle.cshtml it's contents are:
@if (@Model.pageTitle != null){ if(Model.pageTitle.ToString().EndsWith("| Company Name")) { @Html.Raw(Model.pageTitle) } else { @Html.Raw(Model.pageTitle + " | Company Name") }}else{ @Html.Raw(Model.Name + " | Company Name")}
and then in my template am calling it like so:
<title><umbraco:Macro runat="server" language="cshtml">@using umbraco.MacroEngines;@RenderPage("/macroScripts/PageTitle.cshtml");</umbraco:Macro></title>
and
<meta property="og:title" content="@RenderPage("/macroScripts/PageTitle.cshtml")" />
unfortunately @Model.pageTitle is not being picked up..
You can't use @RenderPage directly in your template (like you have done in the meta tag) because the Template page is not a Razor cshtml file.
Also, you can reference a cshtml file directly from a Macro tag without calling RenderPage, like this:
<umbraco:Macro FileLocation="~/macroScripts/PageTitle.cshtml" runat="server" />
Hope that helps.
Alex
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Model not being carried through to render page?
Hi Guys,
just trying to do the following I have a cshtml page called PageTitle.cshtml it's contents are:
@if (@Model.pageTitle != null)
{
if(Model.pageTitle.ToString().EndsWith("| Company Name"))
{
@Html.Raw(Model.pageTitle)
}
else
{
@Html.Raw(Model.pageTitle + " | Company Name")
}
}
else
{
@Html.Raw(Model.Name + " | Company Name")
}
and then in my template am calling it like so:
<title><umbraco:Macro runat="server" language="cshtml">@using umbraco.MacroEngines;@RenderPage("/macroScripts/PageTitle.cshtml");</umbraco:Macro></title>
and
<meta property="og:title" content="@RenderPage("/macroScripts/PageTitle.cshtml")" />
unfortunately @Model.pageTitle is not being picked up..
You can't use @RenderPage directly in your template (like you have done in the meta tag) because the Template page is not a Razor cshtml file.
Also, you can reference a cshtml file directly from a Macro tag without calling RenderPage, like this:
<umbraco:Macro FileLocation="~/macroScripts/PageTitle.cshtml" runat="server" />
Hope that helps.
Alex
is working on a reply...