Skip to content

Instantly share code, notes, and snippets.

@abjerner
Created December 3, 2014 18:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abjerner/ffffaedfd23947beed17 to your computer and use it in GitHub Desktop.
Save abjerner/ffffaedfd23947beed17 to your computer and use it in GitHub Desktop.
Quick guide to insert Contour <script> tags at the bottom of the page rather than in context.

Open /umbraco/plugins/umbracoContour/views/Form.cshtml and look for the following line:

@Html.Partial(FormViewResolver.GetScriptView(Model.FormId), Model)

Replace it with these lines:

List<FormViewModel> temp = HttpContext.Current.Items["ContourScripts"] as List<FormViewModel>;
if (temp == null) {
    HttpContext.Current.Items["ContourScripts"] = temp = new List<FormViewModel>();
}
temp.Add(Model);

Then at the bottom of your master view (or similar), you can add the following lines:

List<FormViewModel> scriptData = HttpContext.Current.Items["ContourScripts"] as List<FormViewModel>;
if (scriptData != null) {
    foreach (FormViewModel model in scriptData) {
        @Html.Partial(FormViewResolver.GetScriptView(model.FormId), model)
    }
}
@dreadpiratebrown
Copy link

For the second part, I had to put it in my master page like this:

@{
List scriptData = HttpContext.Current.Items["ContourScripts"] as List;
if (scriptData != null)
{
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
foreach (FormViewModel model in scriptData)
{
@Html.Partial(FormViewResolver.GetScriptView(model.FormId), model)
}
}
}

Also, had to include these lines at the top of the master:

@using Umbraco.Forms.Core
@using Umbraco.Forms.Mvc.Models;
@using Umbraco.Forms.Mvc.BusinessLogic;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment