We are using Sitecore 7 and MVC + Glass.mapper to build a new site.
Strange thing is that when we use @Editable(x => x.SectionTitle)
, when in Edit mode the SectionTitle
field's content gets HtmlEncoded
, but not in preview or normal mode. (So if there is "" in the title field, it is output as <H1>
in edit mode, but as <H1>
in normal and preview)
If we use @HTML.Sitecore().Field("SectionTitle")
however, it always gets HtmlEncoded, and that is the behaviour we are looking for when using a single line text field...
Is this a Glitch in Glass?
Mike, this is the cshtml code:
<section>
<H2> @Html.Sitecore().Field("SectieTitel")</H2>
<h2>@Editable(x => x.SectieTitel)</h2>
@Html.Sitecore().DynamicPlaceholder("sectieInhoud")
</section>
We generate the models with T4 and TDS, this is the Sectie class generated:
namespace XXXXXXXXXXXXX
{
public interface ISectie : IGlassItem // , ITagging
{
/// <summary>
/// The SectieTitel field.
/// <para></para>
/// <para>Field Type: Single-Line Text</para>
/// <para>Field ID: 2e364ec5-f0d4-4f16-baa3-fa9207f89cf6</para>
/// <para>Custom Data: </para>
/// </summary>
string SectieTitel {get; set;}
}
[SitecoreType(TemplateId="1760c3c6-a623-404a-98be-a0d4335a03cc")]
public partial class Sectie : GlassItem, ISectie
{
private string _sectieTitel;
/// <summary>
/// The SectieTitel field.
/// <para></para>
/// <para>Field Type: Single-Line Text</para>
/// <para>Field ID: 2e364ec5-f0d4-4f16-baa3-fa9207f89cf6</para>
/// <para>Custom Data: </para>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
[SitecoreField("SectieTitel")]
public virtual string SectieTitel
{
get { return _sectieTitel; }
set { _sectieTitel = value; }
}
private object /* UNKNOWN */ _tags;
/// <summary>
/// The Tags field.
/// <para></para>
/// <para>Field Type: Multilist with Search</para>
/// <para>Field ID: 3a837ce8-7a1b-4cbf-8be9-9cebbdf1c48a</para>
/// <para>Custom Data: </para>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
[SitecoreField("Tags")]
public virtual object /* UNKNOWN */ Tags
{
get { return _tags; }
set { _tags = value; }
}
public static string TemplateId { get { return "1760c3c6-a623-404a-98be-a0d4335a03cc"; } }
}
}
In the cshtml you can see that I use the Sitecore MVC field and the glass way. Glass does not output htmlencoded strings while sitecore MVC does in preview and normal...
Erwin
I have made a blog post that details how you could solve this problem.
I will be adding the EncodedString type to the next Glass.Mapper.Sc release. Thanks for the suggestion.