Copied to clipboard

Flag this post as spam?

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


  • leandro koiti 4 posts 24 karma points
    Dec 11, 2013 @ 14:36
    leandro koiti
    0

    how to load templates automatically on v7

    hello, I have a question which I believe is kind of basic but that I couldn't find anything related to it... I'm trying to add a new template file called "MyTemplate.cshtml" inside the "Views" folder, I copied the content from "umbLayout.cshtml" just to test it out, what I was expecting was that when I reloaded the nodes inside Settings -> Templates, a new template called "MyTemplate" would appear, unfortunately that's not what happened.

    I've seen people saying that I only had to add the file to the "Views" folder, is that still true?

    So I added a new Template using Settings -> Templates -> Create and then it not only showed inside the node as I wanted list but created a new file inside the "Views" folder as well.

    How can I do that programmatically? My expectation was to just copy the template inside the "Views" folder the same way I do to the "Partials" folder (I create a new cshtml file inside "Partials", reload the partials nodes and it shows up) but after seeing the node showing up using the backoffice and finding new entries inside the "umbracoNode" and "cmsTemplate" tables I believe something have changed?

    Thanks in advance!

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Dec 11, 2013 @ 17:03
    Tim
    0

    Hiya,

    I think it's always been like that. When you add a template from the back office UI, a record is added to the Umbraco DB table "cmsTemplate". When you copy a view across manually, the record isn't added. I think if you use uSync, it will automatically sync the views up for you when you just copy them across.

  • Ranjit J. Vaity 66 posts 109 karma points
    Dec 12, 2013 @ 10:00
    Ranjit J. Vaity
    0

    Hi Leandro,

    I am facing a same issue in Umbraco 7, when I create a template in ~/Views folder, say "Home.cshtml" it does not shows up in "Settings" -> "Templates" unlike the templates shows up correctly in "Partials Views" as expeceted, if added using VS.

    Also as per Tim's reply, I wanted to tested this in Umbraco 6.x but it worked as expected. ie when I add template (.master file) in "~/masterpages" it showed up under "Settings" -> "Templates". Also umbraco added the entry in umbTemplate table directly even if the template was create using Visual Studio.

    Only difference here is, My previous project was Umbraco 6.x form based and current project is in Umbraco 7  MVC based, so now we try and create template in ~/Views instead if ~/masterpages.

    I won't say Tim is wrong about this as he never mentioned about his Umbraco application was MVC or form based..

    @Tim : It would be great if you share this with us.

    Thanks,

    Ranjit J. Vaity

     

     

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Dec 12, 2013 @ 10:37
    Tim
    0

    Hiya,

    I've only tried with MVC, not web forms. I don't think it's ever automatically picked up the MVC views (although I could be wrong, I've only tried it with the last few v6 releases, not 7 yet).......

    Might be worth logging as an issue on issues.umbraco, especially if master pages work but MVC views don't!

    Cheers,

    Tim.

  • Ranjit J. Vaity 66 posts 109 karma points
    Dec 12, 2013 @ 11:30
    Ranjit J. Vaity
    0

    Hi Tim,

    Yes, I think so. will log this issue for Umb 7.

    I will still have to research on this. I will keep this conversation update with my findings.

    Thank you for your time. :)

    Regards,

    Ranjit J. Vaity

  • leandro koiti 4 posts 24 karma points
    Dec 12, 2013 @ 13:44
    leandro koiti
    0

    hello Tim and Ranjit, thanks a lot for clarifying that out for me! I've tried the same way you did Ranjit, form based on 6.x and using MVC on 7 so I guess I'll do the same and keep the thread updated as well, thanks again!

  • Will Price 12 posts 94 karma points
    Mar 18, 2014 @ 05:19
    Will Price
    0

    I had this same issue - created new .cshtml file in /Views/ folder in Visual Studio and it didn't show in Settings / Templates (Umbraco 7.0.4).

    However for me all I had to do was use the Admin to create a new Template with the exact same name (including capitalisation) as my new .cshtml file, making sure to create it under the correct Master Template, and the admin then correctly showed the template with the correct content.

    Edited to add...

    Once the new Template shows with the same name as your .cshtml file, you may then want to go into the Template Properties to change the display Name (add spaces etc)

  • Ranjit J. Vaity 66 posts 109 karma points
    Mar 21, 2014 @ 11:03
    Ranjit J. Vaity
    0

    Hi Will,

    Thank you for your reponse. But this is what we have to follow through out our development process until there is a fix OR change provided by Umbraco team. Very much like it happens in "Partial View".

    Regards,

    Ranjit

  • Ryios 122 posts 263 karma points
    May 30, 2014 @ 01:17
    Ryios
    0

    I realized this same problem when I tried to use "Umbraco Jet" and realized templates were not being picked up and Umbraco Jet doesn't create them. So I assumed that a previous version of Umbraco must have been doing it automatically and version 7 wasn't.

    I see that I was right...

    I didn't want to have to do this manually in the back office, so I made a Self Contained Class to do it for me using an ApplicationEventHandler and a FileSystemWatcher.

    You can grab a copy on my blog: http://ryiosdotnet.blogspot.com/2014/05/umbraco-7-automatic-template-creation.html

    It's a temporary blog "hence it's uglyness", eventually I'm going to have my own Code First Solution like Umbraco Jet and a nuget package for it.

    Short Summary: The code on the blog will automatically register templates in a running umbraco site when you had a file with a .cshtml extension in the view folder through the Visual Studio Solution Explorer, or Windows Explorer. It also Registers the templates on the Application Started event. So the Automatic Template Creation is for Templates after an Application Start (while the site's running).

    If you are performance weary of having a FileSystemWatcher running on the site's Application Pool just remove the code that does that, it will still Handle the Templates on Application Started.

Please Sign in or register to post replies

Write your reply to:

Draft