简体   繁体   English

如何在 c# razor 中将 OpenGraph 和 Twitter Cards 合并到 2sxc 详细信息模板中?

[英]How can I incorporate OpenGraph and Twitter Cards into a 2sxc details template in c# razor?

I have a listing and details view in a 2sxc app.我在 2sxc 应用程序中有一个列表和详细信息视图。 In the details view, there's lots of content because it's sort of like an article.在详细信息视图中,有很多内容,因为它有点像一篇文章。

I want to put in an OpenGraph and Twitter Cards into the template so that each unique URL in my app has unique content for each article.我想在模板中放入一个 OpenGraph 和 Twitter Cards,以便我的应用程序中的每个唯一 URL 为每篇文章都有唯一的内容。 How can I set up my C# razor template in 2sxc for OpenGraph and Twitter Cards?如何在 2sxc 中为 OpenGraph 和 Twitter Cards 设置我的 C# razor 模板?

I tend to code those things as-needed.我倾向于根据需要对这些东西进行编码。 One big helper we've used recently for the OpenGraph stuff is RazorBlade.我们最近用于 OpenGraph 内容的一个大助手是 RazorBlade。

Razor Blade Tutorials剃须刀教程

Razor Blade home剃须刀之家

Using the docs from Jeremy, I put this into my C# razor template:使用 Jeremy 的文档,我将其放入我的 C# razor 模板中:

@using ToSic.Razor.Blade;

HtmlPage.AddOpenGraph("title", @Content.Name); 
HtmlPage.AddOpenGraph("type", "article");
HtmlPage.AddOpenGraph("url", @Dnn.Tab.FullUrl + "/career/" + Content.urlkey);
HtmlPage.AddOpenGraph("description", "need to determine description somehow");
HtmlPage.AddOpenGraph("image", "https://" + @Dnn.Portal.PortalAlias.HTTPAlias.Replace("/en-ca","").Replace("/fr-ca","") + @Content.Image + "?mode=crop&h=601&w=589&anchor=middlecenter");

This worked for both OpenGraph and TwitterCards.这对 OpenGraph 和 TwitterCards 都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM