TaxonomyField Editor Alternate for specific Field Name

Topics: Customizing Orchard, Writing modules, Writing themes
Jul 24, 2013 at 8:18 PM
Hi All!
Can I add alternative template for Views/EditorTemplates/Fields/TaxonomyField.cshtml?
My picky customer wants it ((
I need to change Titles and Hint for specific Taxonomy Fields in Editor
Thanks in advance!!!
Coordinator
Jul 25, 2013 at 7:25 AM
Jul 25, 2013 at 7:49 AM
Edited Jul 25, 2013 at 7:50 AM
I've already tried this... Did not help me.
I tried Fieelds.TaxonomyField-FieldName etc. in different folders.
Tried <Place> Alternates - not work
Please, can you help me with working example?

I try to alternate Editor template...
Coordinator
Jul 25, 2013 at 8:24 PM
Ah, well, editor shapes do not have those alternates, because it's unusual to override them. You'd have to add one, from a shape table provider for example. See http://weblogs.asp.net/bleroy/archive/2011/01/10/orchard-shapeshifting.aspx Alternates can also be added from placement: http://docs.orchardproject.net/Documentation/Understanding-placement-info#"Place"Element
Jul 25, 2013 at 9:47 PM
Thanks for the reply Bertrand!
But stil But still do not work Alternates(( Not with shape table provider and Alternates in Placement
Can the problem come from Orchard.Taxonomies/Drivers/TaxonomyFieldDriver where in Editor method:
var templateName = settings.Autocomplete ? "Fields/TaxonomyField.Autocomplete" : "Fields/TaxonomyField";
And if so, what can I do with this?

Sorry for bad English...
Coordinator
Jul 26, 2013 at 12:00 AM
Make sure you have the right shape name.
Jul 26, 2013 at 4:45 PM
I'm use Fields_TaxonomyField_Edit
Is that the right shape?
Coordinator
Jul 26, 2013 at 9:58 PM
Yes, that's the right shape. Please show what you tried. What does your placement look like now? Where did you put the alternate template?
Jul 26, 2013 at 10:14 PM
1)
Placement.info in MyModule
<Placement>
  <Place Fields_TaxonomyField_Edit="Content:before;Alternate=Fields_TaxonomyField_Edit_Timbioz"/>
</Placement>
Place TaxonomyField.Edit.Timbioz.cshtml in MyModule/Views/EditorTemplates/Fields

2)
ContentShapeProvider.cs in the root of MyModule:
public class ContentShapeProvider : IShapeTableProvider
    {
        private readonly IWorkContextAccessor _workContextAccessor;

        public ContentShapeProvider(
          IWorkContextAccessor workContextAccessor)
        {

            _workContextAccessor = workContextAccessor;
        }

        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Fields_TaxonomyField_Edit")
              .OnDisplaying(displaying =>
              {
                  ContentItem contentItem = displaying.Shape.ContentItem;
                  if (contentItem.ContentType == "Timbioz.Article")
                  {
                          displaying.ShapeMetadata.Alternates.Add(
                            "Fields_TaxonomyField_Edit_Timbioz");
                      
                  }
              });
        }
    }
Place TaxonomyField.Edit.Timbioz.cshtml in MyModule/Views/EditorTemplates/Fields.....
Coordinator
Jul 27, 2013 at 12:30 AM
Does your module have a dependency on the taxonomies module defined in its module.txt?
Jul 27, 2013 at 11:33 AM
Yes, Dependencies: Orchard.Taxonomies in the module.txt
Coordinator
Jul 27, 2013 at 10:19 PM
If you put a breakpoint in the displaying Lambda, does it get hit?
Jul 29, 2013 at 5:34 PM
Hi!
breakpoint doesn't hit....

But with Alternate=Fields_TaxonomyField_Edit_Timbioz
when i place Fields.TaxonomyField.Edit.Timbioz.cshtml in the root of Views folder
it working, but throws error:
The model item passed into the dictionary is of type 'Orchard.DisplayManagement.Shapes.Shape', but this dictionary requires a model item of type 'Orchard.Taxonomies.ViewModels.TaxonomyFieldViewModel'.
Source File: f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs Line: 142
Stack Trace:
[InvalidOperationException: The model item passed into the dictionary is of type 'Orchard.DisplayManagement.Shapes.Shape', but this dictionary requires a model item of type 'Orchard.Taxonomies.ViewModels.TaxonomyFieldViewModel'.]
   System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +383
   System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +625
   System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +74
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +137
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +158
   Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:142
   Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.<>c__DisplayClass28.<Discover>b__15(DisplayContext displayContext) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:126
   Orchard.DisplayManagement.Descriptors.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:179
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:88
   Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:86
   Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:44
   Orchard.DisplayManagement.Implementation.DisplayHelper.TryInvoke(InvokeBinder binder, Object[] args, Object& result) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:29
   CallSite.Target(Closure , CallSite , Object , Object ) +220
   Orchard.Core.Shapes.CoreShapes.ContentZone(Object Display, Object Shape, TextWriter Output) in f:\Orchard\scru\src\Orchard.Web\Core\Shapes\CoreShapes.cs:274

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +76
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.ShapeAttributeBindingStrategy.PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, Object serviceInstance) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:64
   Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.<>c__DisplayClass4.<CreateDelegate>b__3(DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:55
   Orchard.DisplayManagement.Descriptors.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:179
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:88
   Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:86
   Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:44
   Orchard.DisplayManagement.Implementation.DisplayHelper.TryInvoke(InvokeBinder binder, Object[] args, Object& result) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:29
   CallSite.Target(Closure , CallSite , Object , Object ) +220
   System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site, T0 arg0, T1 arg1) +975
   ASP._Page_Core_Contents_Views_Content_Edit_cshtml.Execute() in f:\Orchard\scru\src\Orchard.Web\Core\Contents\Views\Content.Edit.cshtml:5
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +158
   Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:142
   Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.<>c__DisplayClass28.<Discover>b__15(DisplayContext displayContext) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:126
   Orchard.DisplayManagement.Descriptors.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in f:\Orchard\scru\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:179
   Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:88
   Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:86
   Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:44
   Orchard.DisplayManagement.Implementation.DisplayHelper.TryInvoke(InvokeBinder binder, Object[] args, Object& result) in f:\Orchard\scru\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:29
   CallSite.Target(Closure , CallSite , Object , Object ) +220
   System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site, T0 arg0, T1 arg1) +975
   ASP._Page_Core_Contents_Views_admin_Create_cshtml.Execute() in f:\Orchard\scru\src\Orchard.Web\Core\Contents\Views\Admin\Create.cshtml:15
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   Orchard.Mvc.ViewEngines.ThemeAwareness.<>c__DisplayClass7.<FindView>b__5(ViewContext viewContext, TextWriter writer, IViewDataContainer viewDataContainer) in f:\Orchard\scru\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:59
   Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutView.Render(ViewContext viewContext, TextWriter writer) in f:\Orchard\scru\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:90
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
Jul 29, 2013 at 5:35 PM
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +854224
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +40
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in f:\Orchard\scru\src\Orchard\Mvc\Routes\ShellRoute.cs:159
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
Developer
Jul 29, 2013 at 6:07 PM
So you created an alternate edit view. Did you include the model declaration as well? E.g.
@model TaxonomyFieldViewModel
Jul 29, 2013 at 6:15 PM
Edited Jul 29, 2013 at 6:15 PM
Yes of course, @model TaxonomyFieldViewModel in the top of my .cshtml file
It is the same file from Orchard.Taxonomies module. In it I changed only the Hint text (for testing working or not alternate)
Developer
Jul 29, 2013 at 6:40 PM
Interesting. Sorry, then I don't know.
Coordinator
Jul 29, 2013 at 11:31 PM
Remove the @model directive from your view, then place a breakpoint in your view and examine Model.
Jul 30, 2013 at 9:19 AM
When i remove @model directive and place breakpoint on bool IsTermDisabled(TermEntry term) { in:
@functions {
    bool IsTermDisabled(TermEntry term) {
        return !term.Selectable || (Model.Settings.LeavesOnly && Model.Terms.Any(t => t.Path.Contains(term.Path + term.Id)));
    }
}
First i get error: HttpCompileException:
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"} 
in src\Orchard\Mvc\ViewEngines\ThemeAwareness\ViewEngineCollectionWrapper.cs
line 17
 var result = engine.FindPartialView(controllerContext, partialViewName, useCache);
Then i get error: TargetInvocationException:
Exception has been thrown by the target of an invocation
in src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs
line 64:
var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());
Finaly i have error CS1977 (see above) in line with my breakpoint (but breakpoint dosen't hit)..... Oo
Coordinator
Jul 30, 2013 at 9:53 PM
Do you get an error with an empty view?
Jul 31, 2013 at 4:54 PM
Hello again)

With an empty view i dont get errors...
Coordinator
Jul 31, 2013 at 8:07 PM
OK, so the error is now introduced by some of your code (you didn't include the full stack trace so I had to guess here). You can try to add code back little by little, to determine what exactly is failing, or you can examine the full stack trace from your previous version of the template that was failing and find out this way what's wrong. Not seeing your code, I can't guess any further.
Oct 21, 2013 at 1:25 PM
Late to the game here but I read through this hoping for some resolution and didn't find any. I can add a description though for what is going on. When you use the alternate in Placement.info, it is actually adding a wrapper of some sorts, I will refer to it as a "Shape Wrapper". Therefore, each of the editor fields original model is stored in Model.Model. As a full example of this, if you want to override Fields.Input.Edit.cshtml, you need to add the override name in your "View" folder (not the EditorTemplates" folder since the alternate won't be looked for there. I have called mine "Fields.Input.Edit.Override.cshtml" and here is my placement.info:
<Place Fields_Input_Edit="Content:2.4;Alternate=Fields_Input_Edit_Override"/>
And here is my Fields.Input.Edit.Override.cshtml (note that my html is edited from the original to accomplish my "look"):
@using Orchard.Utility.Extensions;
@using Orchard.Fields.Settings;
@{
    // Have to get actual Model
    var fieldModel = (Orchard.Fields.Fields.InputField)Model.Model;
    var settings = fieldModel.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();

    // Cannot use Html Helper Html.FieldIdFor and Html.FieldNameFor since our context has now changed 
    //  - i.e. Model is not what what the normal form editor is expecting as wrapped in a Shape
    string contentType = Model.ContentItem.ContentType;
    string fieldId = String.Format("{0}_{1}_Value", contentType, fieldModel.Name);
    string fieldName = String.Format("{0}.{1}.Value", contentType, fieldModel.Name);
}

<div class="form-group">
    <label class="sr-only" for="@fieldId">@fieldModel.DisplayName</label> 
    @if (settings.Required) {
        <span class="sr-only required">*</span>
    }   
    <input class="form-control" type="@settings.Type.ToString().ToLower()" id="@fieldId" name="@fieldName" @if(!String.IsNullOrWhiteSpace(settings.Title)) {<text> title="@settings.Title"</text>} value="@fieldModel.Value"@if(settings.Required) {<text> required="required"</text> }@if(settings.AutoFocus) {<text> autofocus="autofocus"</text> }@if(settings.AutoComplete) {<text> autocomplete="on"</text> }@if(!string.IsNullOrWhiteSpace(settings.Placeholder)) {<text> placeholder="@settings.Placeholder"</text>}@if(!string.IsNullOrEmpty(settings.Pattern)) {<text> pattern="@settings.Pattern"</text>}@if(!string.IsNullOrEmpty(settings.EditorCssClass)) {<text> class="@settings.EditorCssClass"</text>} else {<text> class="textMedium"</text>} @if(settings.MaxLength > 1) {<text> maxlength="@settings.MaxLength.ToString()"</text>} />
    @Html.ValidationMessage(fieldName)
    @if (!String.IsNullOrEmpty(settings.Hint)) {
        <p class="help-block">@settings.Hint</p>
    }
</div>
The main points are:
  1. you need to get back your "Model" (I call it "fieldModel")
  2. You cannot use Html.LabelFor or Html.InputFor helpers to build up your field Name and Id attributes because the context is now all wrong (i.e. the MVC Model is actually the Shape wrapper so it will be built incorrectly) - you can use @Html.Label and @Html.Input of course by passing in your Name and Id string
This works great for the Input field, but not so great for the Fields.Common.Text.Edit field as it has this line of code in it:
@Display.Body_Editor(Text: Model.Text, EditorFlavor: settings.Flavor)
Unfortunately, there is no way to pass in the Id or Name and it builds them based on the current context. This means it always comes out with an Id and Name of "Text" which is useless when posting back content.

I am exploring options as I feel it is very powerful to use alternates with the Editor fields. The only thing that needs done is to somehow get rid of the Shape Model... I am open to ideas.
Feb 7 at 5:03 PM
jao28, brilliant, thanks!

It's not pretty but I've come up with the following to bypass wrapper shape:
@using Orchard.Fields.Settings;
@{
    var fieldModel = (Orchard.Fields.Fields.InputField)Model.Model;
    var settings = fieldModel.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
    
    string contentType = Model.ContentItem.ContentType;

    var viewDataCopy = new ViewDataDictionary(ViewData) {
                Model = fieldModel,
                TemplateInfo = new TemplateInfo {
                    HtmlFieldPrefix = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(contentType + "." + fieldModel.Name)
                }
    };
}

@Html.Partial("testEditorTemplate", fieldModel, viewDataCopy)
And do formatting in testEditorTemplate.cshtml, using Model as in the original field editor template..

For text field it works as well:
@using Orchard.Utility.Extensions;
@using Orchard.Core.Common.ViewModels;
@{
    var fieldModel = (TextFieldDriverViewModel)Model.Model;
    
    string contentType = Model.ContentItem.ContentType;

    var viewDataCopy = new ViewDataDictionary(ViewData) {
                Model = fieldModel,
                TemplateInfo = new TemplateInfo {
                    HtmlFieldPrefix = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(contentType + "." + fieldModel.Field.Name)
                }
    };
}

@Html.Partial("testTextFieldEditorTemplate", fieldModel, viewDataCopy)