0

Desired output

<a data-toggle="dropdown">Countries <i class="fa fa-angle-down"></i></a>

View:

  @Html.Sitecore().BeginField("Target URL", item.Item, new { @data_toggle = "dropdown" })
  <i class="fa fa-angle-down"></i>
  @Html.Sitecore().EndField()

Rendered html:

<a href="#" data_toggle="dropdown">Countries <i class="fa fa-angle-down"></i></a>
  1. href is generated. It is not needed.
  2. The data-toggle attribute isn't set.
7
  • What's wrong with <a data-toggle="dropdown">@item.Item<i class="fa fa-angle-down"></i></a>? Commented Mar 31, 2016 at 11:51
  • 1
    @qwerty Have you seen brad-christie.com/blog/2014/09/24/… ? Commented Mar 31, 2016 at 11:53
  • @MarekMusielak. Yes.Been there. Where to create the Process(RenderFieldArgs args)? Should I create a new config file?If yes, then how to register it. Hard to figure all this for a beginner. Commented Mar 31, 2016 at 12:08
  • @Liam. But would that make the field editable? Commented Mar 31, 2016 at 12:08
  • 1
    Yes. In the experience editor. Not using Glass mapper Commented Mar 31, 2016 at 12:20

1 Answer 1

0

An edit frame or edit-mode check are possible solutions, but you could also create your own extension to the HtmlHelper from Sitecore. Just to give you an idea:

public static HtmlString Test(this SitecoreHelper helper, string fieldName, Item item, object parameters)
{
    var result = helper.BeginField(fieldName, item, parameters);
    return new HtmlString(result.ToString().Replace("href=\"#\" ", string.Empty));
}

This quick example will remove the href="#" but you can make it more intelligent.

In your View you can use:

@Html.Sitecore().Test("Target URL", item.Item, new { @data_toggle = "dropdown" })
<i class="fa fa-angle-down"></i>;
@Html.Sitecore().EndField()

Just some quick test code but it should work already and can be extended to get you what you need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.