Reputation: 1540
Using a master template, the idea was to be able to pull the meta tags and descriptions from Umbraco. Originally the Master template page was using WebForms, However the whole project has been converted to Razor pages. So the meta tags and descriptions were pulled from Umbraco using the following:
<umbraco:Item field="MetaKeywords" insertTextBefore="<meta name="keywords" content="" insertTextAfter="" />" runat="server"></umbraco:Item>
<umbraco:Item field="MetaDescription" insertTextBefore="<meta name="Description" content="" insertTextAfter="" />" runat="server"></umbraco:Item>
However after doing some reading (and correct me if i'm wrong) the umbraco item tag cannot be used with the razor syntax. I am no expert and am fairly knew to Umbraco etc. Is there a way I can perform the same functionality using razor pages? As it stands using the above code, Visual studio will say that umbraco tag is an unrecognised namespace.
This is an MVC project if that provides any further complications/information. Thanks in advance, any help will be greatly appreciated.
Upvotes: 0
Views: 1173
Reputation: 8049
Old post, but figured I'd add solution I found for MVC
https://our.umbraco.org/forum/using/ui-questions/22198-Meta-Tags
The reason why this old solution not works for you is that, it´s for websites that running in WebForms mode. Since you are using Umbraco 7.2.2, it uses MVC as default,
In MVC templates you can called it like this.
@Umbraco.Field("AliasOfTheField")
https://our.umbraco.org/Documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper
So for the meta description, and meta keywords it would look like this.
@Umbraco.Field("metaDescription")
@Umbraco.Field("metaKeywords")
Upvotes: 3
Reputation: 1540
I have managed to get this to work now. For anyone else that comes across this issue in the future this is how I got it to work. I checked if the current page had the property I was looking form, then I assigned the keywords and descriptions based on that property.
@if (CurrentPage.HasProperty("SeoKeywords") && CurrentPage.HasProperty("SeoDescription"))
{
<meta name="keywords" content="@CurrentPage.SeoKeywords" />
<meta name="description" content="@CurrentPage.SeoDescription" />
}
On Umbraco the base page document type that I am working with, has a property for both the keywords and descriptions, each with an alias name. That alias name is what I was checking the CurrentPage.HasProperty("") for.
This now works for me. Hope this may help provide a little bit of help to anyone else. Also thanks to 'Exception' for clarifying the original question.
Upvotes: 1
Reputation: 18873
No Umbraco tags are not supported(till now as shown in your question) in simple razor engine
based web app you have to use either htmlhelpers or html tags in asp.net mvc.
for ex :-
@Html.TextBoxFor(),@Html.TextArea()
...or simple html tags only..
Upvotes: 0