edit custom mvc widget template

Posted by Community Admin on 04-Aug-2018 12:13

edit custom mvc widget template

All Replies

Posted by Community Admin on 15-Feb-2016 00:00

Hello,

I'm in the process of creating a flickr  MVC widget. I want to know if there is a possibility that backend users can edit the template (mvc view) in the administration part of sitefinity? I thought about using Design >> wiget template but I don't think this is used to edit "MVC" widgets only webforms. Any idea?

Thank you,

Kr,

 

Jordi

Posted by Community Admin on 18-Feb-2016 00:00

Hello Jordi,

The views of the MVC widgets, including the Feather ones, could be edited in any editor. There is no need to use Visual Studio.
In the the Design > Widget templates you have web forms templates and the Dynamic modules MVC templates also..

You can try to register the template in the backend like:

public void RegisterTemplate()
    var area = "MyController"; // The controller name
    var condition = "MyController MVC";
    var controlType = typeof(MultilineTextController).FullName;
  
    var listTemplateName = "List.Test"; // The view template name
    var friendlyControlList = "MyController list (MVC)";
    var nameForDevelopersList = listTemplateName.Replace('.', '-');
    var path = Server.MapPath("~/Mvc/Views/MyView/List.Default1.cshtml"); // physical file to be used to extract razor syntax markup
    var content = this.GetViewContentFromFileSystem(path);
    var listTemplate = this.RegistereTemplate(area, listTemplateName, nameForDevelopersList, friendlyControlList, content, condition, controlType);
    // restart after creating the template
    SystemManager.RestartApplication(OperationReason.UnknownReason(), SystemRestartFlags.Default);
  
private string GetViewContentFromFileSystem(string path)
    var templateText = string.Empty;
    bool fileExists = System.IO.File.Exists(path);
    if (fileExists)
    
        templateText = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8);
    
    else
    
        throw new FileNotFoundException("File not found! Path: " + path);
    
  
    return templateText;
  
private ControlPresentation RegistereTemplate(string area, string name, string nameForDevelopers, string friendlyControlName,
    string content, string condition, string controlType)
    var pageManager = PageManager.GetManager();
    var template = pageManager.GetPresentationItems<ControlPresentation>()
        .Where(cp => cp.NameForDevelopers == nameForDevelopers
        && cp.AreaName == area && cp.Condition == condition)
        .FirstOrDefault();
    if (template == null)
    
        template = pageManager.CreatePresentationItem<ControlPresentation>();
    
  
    template.AreaName = area;
    template.Data = content;
    template.Condition = condition;
    template.ControlType = controlType;
    template.Name = name;
    template.NameForDevelopers = nameForDevelopers;
    template.FriendlyControlName = friendlyControlName;
    template.IsDifferentFromEmbedded = true;
    template.DataType = Presentation.AspNetTemplate;
    var versionManager = VersionManager.GetManager();
    versionManager.CreateVersion(template, true);
  
    pageManager.SaveChanges();
    // Create a version of the template for Revision History
    versionManager.SaveChanges();
  
    return template;

I hope this helps.

Regards,
Svetoslav Manchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 18-Feb-2016 00:00

Sorry I think I have to rephrase. Ialready have custom mvc widget working (residing in a seperate assembly). Now I want to know if it is possible for backend users to modify the view? I don't think so maybe cause the view is an embedded resource? Or is there..

Thank you for your help

 

Kr,

 

Jordi

Posted by Community Admin on 22-Feb-2016 00:00

Hi Jordi,

As the view is embedded resource and in case you want to provide such functionality for the users to amend the view in the Backend you need to register it as described before.
Thus the view will be available for edit under Design > Widget templates.

Regards,
Svetoslav Manchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed