So I am trying to create a script whereby depending on the document type of the page a certain pre-defined title tag format will appear, if there is nothing already written in an overwriting custom title input. I have inserted the macro within the title
tag on my master template but keep on getting an Error loading Razor Script message .
Html
<title>
<umbraco:Macro Alias="NewPageTitle" runat="server"></umbraco:Macro>
</title>
Script -
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.MacroEngines
@{
if(String.IsNullOrEmpty(@Model.tabName.ToString()) == false )
{
@Model.tabName
}
else if(@Model.DescendantsOrSelf("Country"))
{
<text>
Holidays in @Model.Name
</text>
}
else
{
@Model.Name;
}
}
Any help would be greatly appreciated.
Try this code out. The problem with your original code is that you were using "@Model.DescendantsOrSelf("Country")" as a boolean, and it is a list. I also removed your comparison for if(String.IsNullOrEmpty(@Model.tabName.ToString())).
Also, if you add ?umbDebugShowTrace=true to the end of your URL, you can get some valuable debugging information. There is a Chrome Extension called "Umbraco Debug" that I use to quickly access that query string and information. You may find it useful.