VanDerPrygel
VanDerPrygel

Reputation: 91

Meta description with special characters in Umbraco

I have a problem when using special characters in meta and alt text in Umbraco.

I am testing with Meta description and Alt text like this: Test test æøå

And it generates this output:

<meta name="description" content="Test test &#230;&#248;&#229;">

<img src="#" alt="Test test &#230;&#248;&#229;" />

If I insert the same text in title tags and normal content, then the output is just perfect.

The code that is generating the meta and title tags looks like this:

<!DOCTYPE html>
<html lang="da">
<head>
  <meta charset="utf-8">
  <meta name="description" content="@Umbraco.Field("pageDescription")">
  <title>@Umbraco.Field("pageTitle")</title>
</head>

The files are saved as utf-8 using Notepad++.

If I insert æøå directly in the HTML, then it shows æøå without any problems.

I have also tried this:

<p>@Umbraco.Field("pageDescription")</p>

And then it shows "æøå" correctly.

Does anybody know what I am doing wrong?

Thanks in advance!

// René

Upvotes: 4

Views: 1497

Answers (1)

sebastiaan
sebastiaan

Reputation: 5917

Looks like this is a "feature" of Razor that it will always HTML encode attributes. See: Razor - @Html.Raw() still encoding &amp; in meta tag attributes

So to work around this, you can do the following:

<meta name="description" @Html.Raw("content=\""+ @Umbraco.Field("pageDescription") + "\"") />
<title>@{ var title = new HtmlString(Umbraco.Field("pageTitle").ToString());}@title</title>

It's not pretty, but it works.

Upvotes: 4

Related Questions