Customizing Script.cshtml to remove inline loading of contourform.js
Based on the custom markup, "Customizing for a specific form" example, we'd like to load our own Script.cshtml to allow us to remove the reference the contourform.js and load it at the bottom of our page, above the closing </body> tag (following best practices). As we would prefer to load jquery after all the markup has loaded, the placement of this script breaks our pages where a form is being loaded before jquery is loaded. We're prefer not to overwrite the Script.cshtml, but if required, we may have to.
@Skowronek, did you have any luck with this? I've done the same thing to disable the loading of contourform.js in Script.cshtml and loading it at the bottom of the page after jQuery, which works fine. Except for the inline script chunk with all the PopulateFieldValues-stuff that Contour outputs before the form, and which fails when jQuery hasn't loaded yet. Have you had any luck working around that?
I hate having built a whole site around best-practices and loading all scripts at the bottom of the page, and then having to throw all of that overboard as soon as Contour is installed.
We were able to accomplish this by using our own Contour user controls that were modified to do what we needed with a bunch of onload overrides and such. Nasty hacks but the only way to do it with .NET controls method.
Here are the basics, and yes, we had to do all of this to get it to work right with Bootstrap.
Create your own render form control and place it in your Umbraco controls folder (wherever you have it)
Set the control to the Controur form in the back office to use your new control rather than the default one provided by Umbraco
You need to customis the form that you are generating the view for by editing the form.cshtml file (either the global one or individual form ones [/Umbraco/Plugins/umbracoContour/Views]) and remove/comment out the line that adds the scripts to the page
Customizing Script.cshtml to remove inline loading of contourform.js
Based on the custom markup, "Customizing for a specific form" example, we'd like to load our own Script.cshtml to allow us to remove the reference the contourform.js and load it at the bottom of our page, above the closing </body> tag (following best practices). As we would prefer to load jquery after all the markup has loaded, the placement of this script breaks our pages where a form is being loaded before jquery is loaded. We're prefer not to overwrite the Script.cshtml, but if required, we may have to.
Thanks.
Comment author was deleted
Yeah you can customize :) if you send the adjustments I could add it as a default option...
@Skowronek, did you have any luck with this? I've done the same thing to disable the loading of
contourform.js
inScript.cshtml
and loading it at the bottom of the page after jQuery, which works fine. Except for the inline script chunk with all the PopulateFieldValues-stuff that Contour outputs before the form, and which fails when jQuery hasn't loaded yet. Have you had any luck working around that?I hate having built a whole site around best-practices and loading all scripts at the bottom of the page, and then having to throw all of that overboard as soon as Contour is installed.
Guess not: http://our.umbraco.org/forum/umbraco-pro/contour/38540-Position-of-javascript
Argh.
Anyone have an update on this? This thing is biting me in the ass as well...
We were able to accomplish this by using our own Contour user controls that were modified to do what we needed with a bunch of onload overrides and such. Nasty hacks but the only way to do it with .NET controls method.
Here are the basics, and yes, we had to do all of this to get it to work right with Bootstrap.
ContourRenderForm.ascx
ContourRenderForm.ascx.cs
In case someone else stumbles across this and thinks there's no solution, there is a way that we've been doing it in MVC
You need to include references to:
You then need to create a new instance of FormViewModel:
You can then render your script partial with:
Wherever you want, either directly on your master page if you form is there, or using an @Section block if it's a chil page.
Hopefully that will help someone, may even be possible from WebForms, though I'm yet to try and find a way.
Mark
Mark,
The Script partial worked for me, but how to have the form be written without the script tags in the first place?
Kevin
Hi Kevin,
Should have put it in my post I suppose :-s
You need to customis the form that you are generating the view for by editing the form.cshtml file (either the global one or individual form ones [/Umbraco/Plugins/umbracoContour/Views]) and remove/comment out the line that adds the scripts to the page
This will mean that the script partial will only be added where you have put it in your own master/content page.
Hope that helps..
Mark
Comment author was deleted
There is also this guide: https://gist.github.com/abjerner/ffffaedfd23947beed17
Even better, thanks Tim. Though it looks like that was only created 2 days ago so couldn't have seen it before lol :-)
is working on a reply...