Search code examples
c#razordotnetnuke2sxc

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. 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. How can I set up my C# razor template in 2sxc for OpenGraph and Twitter Cards?


Solution

  • Using the docs from Jeremy, I put this into my C# razor template:

    @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.