If you want to get the meta values from a node, you should inject IMetaFieldsService and pass the currentPage. This will then give back a model with all the values you want.
var title = string.IsNullOrWhiteSpace(Model.Value<string>("pageTitle")) ? Model.Name : Model.Value<string>("pageTitle") ;
// Set the ViewBag title with the fallback and the appended string
ViewBag.Title = $"{title} | GGUSD";
var pageTitle = Model?.PageTitle;
var seoMetaData = SeoMetaDataService;
SeoToolkit how to get Meta data in code
Hi, I use SeoToolkit plugin 2.3.0 with Umbraco 10
The question is how to get Meta data for current page from the code?
I tried to do this in this way:
But no result.
I need this to reuse this metadata for Microdata shema.org
Hi Dan,
If you want to get the meta values from a node, you should inject IMetaFieldsService and pass the currentPage. This will then give back a model with all the values you want.
An example can be found here: https://github.com/patrickdemooij9/SeoToolkit.Umbraco/blob/dev/Umbraco11/src/SeoToolkit.Umbraco.MetaFields.Core/Common/TagHelpers/MetaFieldsTagHelper.cs
Hey Dan,
How do I access the Meta values in a razor file. I injected the service to my razor view but how do I pass the current page to it?
@using Umbraco.Cms.Web.Common.PublishedModels; @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; @using SeoToolkit.Umbraco.MetaFields.Core.Models; @using SeoToolkit.Umbraco.MetaFields.Core.Services; @inject SeoToolkit.Umbraco.MetaFields.Core.Interfaces.Services.IMetaFieldsService SeoMetaDataService;
@{ Layout = "Master.cshtml";
}
is working on a reply...