Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ryios 122 posts 263 karma points
    Jun 04, 2015 @ 09:56
    Ryios
    0

    Route hijack with no templates set on document type?

    I'm developing a plugin that will host it's own views folder in the App_Plugins/XYZ/Views location.

    I added that folder to the view engine location and I can render views in there just by specifying the view name without making a custom view engine.

    However template hijacking is all kinds of broken I think.

    To automate everything I create the Templates in code (they exist on physical disk in the App_Plugins folder).

    I also create my document types, property editors, data types, etc in code as well (all in the right order).

    Now, the problem is Template based route hijacking requires that the document type have a template set (I'd like to not do this and still have template hijacking...).

    So in order to have a template set I register the templates via code like this,

                string masterTemplatePath = "\\App_Plugins\\TLCKB\\Views\\TLCKBMaster.cshtml";
            string categoryTemplatePath = "\\App_Plugins\\TLCKB\\Views\\TLCKBCategory.cshtml";
            Template masterTemplate = (Template)fileService.GetTemplate("TLCKB_Master");
            if (masterTemplate == null)
            {
                masterTemplate = new Template(masterTemplatePath, "TLCKBMaster", "TLCKBMaster");                
            }
    

    I've tried the path there about 10,000 different ways, I've tried ~/ url syntax or just / url syntax.. I have tried HttpContext.Current.Server.MapPath to get the exact physical filename and path of the view (template).

    However when I save the template I don't see the content from the view in App_Plugins in the database.

    Secondly if I add some text to the template in the back office and save it, it saves to ~/Views/TemplateAlias.cshtml as if to completely ignore any path I set.

    I'm begging to think Umbraco 7 (7.2.1) and other versions I've used don't actually do anything with the path in the context of a template. I think Path is just there because Template Inherits from File, and File is used for Media Items and Uploads and Other things.

    This is a huge oversite in my opinion, I don't want me plugins views to be in the root of the Views folder (could be name conflicts, or lead to me doing something like XYZUmbracoPluginMasterTemplate_.cshtml to be sure it's unique to the world..)

    Alternatively... if there is a way I can hijack routes for my document types and redirect to templates in other folders without having a template on my document types I could do that. In other words my document types would have no allowed template and no default template and would still work and load all my views in App_Plugins..

    To tie this up, it actually works in that my routes render and load my templates in appplugins, the issue isn't that it doesn't work. The issue is my solution basically ignores the template in the views folder and users cannot see the AppPlugins view in the back office, but they will see a view that matches the correct alias.

    In other words, the flow is broken. users see templates in the Back office for my plugin, but see no code in them, and if they save code they don't see it render.

    If I could tie these up somehow that would be super.

    I'm considering even doing something hacky like generating hard links with mklink at AppStartup so that the views in Views\ link to App_Plugins\XYZ\Views, which would work, but is a hack.

  • Ryios 122 posts 263 karma points
    Jul 15, 2015 @ 15:08
    Ryios
    0

    I eventually removed my need for Template Hijacking and went with just Route Hijacking on Index.

    I created a Mode request parameter and I run different views based on the mode,

    --Normal Mode-- /mycontent/?Mode=

    --RedirectToContent-- /mycontent/?Mode=Redirect&ContentId=1046

    --New Post-- /mycontent/?Mode=NewPost

    --Edit Post-- /mycontent/?Mode=EditPost&ContentId=1046

    etc, etc, etc.

Please Sign in or register to post replies

Write your reply to:

Draft