Copied to clipboard

Flag this post as spam?

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


  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Aug 06, 2015 @ 13:01
    Frans de Jong
    0

    Render forms partial view directly in template

    Hi all,

    I have taken on a challenge with umbraco forms.

    I need to load a different forms.cshtml on one DocumentTypeAlias. I thought of changing the forms.cshtml to

    @If(CurrentPage.DocumentTypeAlias == "SpecialForm"){
    //Special layout
    }else
    {
    //normal layout
    }
    

    But offcourse the name CurrentPage doesn't exist...

    I also need to load a different image on every FormStep. The problem with this is the same as the problem discribed above... I can't do

    @CurrentPage.Image1
    

    Can anybody point me in the right direction? There is no documentation of Forms that I can find...

    Who can point me in the right direction?

    Thanks, Frans

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Aug 06, 2015 @ 20:31
    Dennis Aaen
    1

    Hi Frans,

    If you run the latest nightly of Umbraco Forms then you have the options to customizing for a specific form. http://nightly.umbraco.org/UmbracoForms/nightlies/

    For a specific form you'll need to create the following folder: /App_Plugins/UmbracoForms/Data/forms/{FormId}/ (FormId needs to be an existing form id, you can find the id of the form in the URL when you are on the form)

    As an example if your form id is 85514c04-e188-43d0-9246-98b34069750c then you can overwrite the form view by adding the Form.cshtml file to the directory First copying the default one and then making your changes is the best way to get started /App_Plugins/UmbracoForms/Data/forms/85514c04-e188-43d0-9246-98b34069750c/Form.cshtml

    Then I think that you can do some thing like this directly in on of your templates.

    @If(CurrentPage.DocumentTypeAlias == "SpecialForm"){
         @Umbraco.RenderMacro("FormsRenderForm", new {FormGuid="85514c04-e188-43d0-9246-98b34069750c"})
    }else
    {
         @Umbraco.RenderMacro("FormsRenderForm", new {FormGuid="3673bf87-e96e-41d0-a1d9-831ed8412205"})
    }
    

    Remember to change the form GUID´s so it match your case.

    Hope this helps,

    /Dennis

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Aug 07, 2015 @ 08:22
    Frans de Jong
    0

    yesterday I was fooling around with this problem and found a different solution.

    In the document type SpecialForm I have a FormPicker. In the template I render the form the normal way:

        @Umbraco.RenderMacro("umbracoformsRenderForm", new {FormGuid="6bf71d72-5186-416f-b0bb-0bedac65d66a"})
    

    On the form Partial View I compare the Guid of the current form and the special form. If it's a match I use the special layout else I use the default form.

        @{
            var SpecialFormNode= new umbraco.NodeFactory.Node(SpecialFormNodeId);
            string SpecialFormGuid = SpecialFormNode.GetProperty("SpecialForm").Value;
            string CurrentFormGuid = Model.FormId.ToString();
    }
    
    @if(@SpecialFormGuid == @CurrentFormGuid)
    {
    //SpecialForm Layout
    }
    else
    {
    //Normal layout
    }
    

    Now I can access content of the SpecialFormsNode with:

    SpecialFormNode.GetProperty("img1").Value;
    

    I don't know if this is the most efficient way to go, but for me the advantage is that I'm able to change both layouts in one partial view that I can access via Umbraco without the use of Visual Studio.

    Does anyone foresee a problem with this solution?

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Aug 07, 2015 @ 13:35
    Frans de Jong
    0

    Still one problem left....

    I need to acces media from the forms.cshtml but the namespace doesn't exist and I have no idee how to include it. @Include doesn't work becouse forms uses @model and there can only be one @model in a partial view...

    Any thoughts?

    Edit: I was able to get the Id of the image I want but I can't get the URL or the Name...

Please Sign in or register to post replies

Write your reply to:

Draft