Copied to clipboard

Flag this post as spam?

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


  • Paul 24 posts 114 karma points
    May 06, 2015 @ 18:44
    Paul
    0

    Using MNTP with Web Forms

    Hi, I have upgraded a website to v7 and am in the process of rebuilding some of the now defunct uComponents pickers.

    I have replaced a picker with a new MNTP Datatype and added it to my DocType. I added a parameter called widgetList to the Datatype as the uComponents picker had originally. I have also added similar macros to the originals.

    The data in the old uComponents picker seemed to be accessed using

    <umbraco:Macro Alias="ShowWidgets" runat="server" widgetList="[#sideWidgets]" >
    

    from Homepage.master.

    The selected nodes could be picked up with the following macro (for demonstration):

    @using System.Xml;
    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        string list = Parameter.widgetList;
    }
    
    @list
    

    I have tried similar methods with the new MNTP, using the same [#...] syntax but with no luck. How can I access the node ids with MNTP?

    I know the code really needs changing to Razor syntax, and this will happen in the future but it is outside of my spec unless absolutely necessary.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 06, 2015 @ 19:38
    Dennis Aaen
    0

    Hi Paul,

    Since you have upgraded your site to version 7, there are some differences to the Razor, as you already experiences. When you are using the Umbraco 7 or upgrade from a older version you need to convert your old dynamicNode Razor scripts to partial views or partial view macros.

    It is not so hard to convert it. the @Model, is @CurrentPage in the dynamic Razor and in the stongly typed version @Model is @Model.Content. you can see more about converting legacy Razor MacroScript to partial view macros here http://our.umbraco.org/documentation/reference/templating/macros/Partial-View-Macros/#ConvertingaPartialViewMacrofromalegacyRazorMacroScript

    You can create partial view in the settings section, and partial view macro files in the developer section. In your case where you need to pass a macro in you need to use partial view macro files. And you are called it in your template like this if you are in MVC, but in WebForms you can do it like you normally use to do.

    @Umbraco.RenderMacro("NameOfTheFile")

    In your case you also try to pass a macro in to the file, be sure that you have add the macro parameter to the macro, under the developer section --> Macros --> Find the macro and click it and choose the parmeter tab.

    After you have added it you can called it like this:

    @Model.MacroParameters["parameterAlias"]

    I think that you will get a lot of help by having a look at the Umbraco v6 MVC Razor Cheatsheets there are overview of the different Razor methods, both the dynamic version and the strongly typed version. https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets I know it says for v6, but you can also use it for v7. And it´s is PDF files.

    For the part on how to get data from the multi node tree picker, have a look at this https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Multinode-Treepicker documentation. As you can see there are code examples for both implementations of Razor, the dynamic version and the strongly typed.

    Hope this helps,

    /Dennis

  • Paul 24 posts 114 karma points
    May 07, 2015 @ 11:53
    Paul
    0

    Thanks for you reply Dennis, I think my first problem is much more basic.

    I have changed all of my original masterpages to razor views, thanks for the advice there, and they all seem to work as before.

    However I cannot seem to see any of my new widgets. For example, I have an old uComponent picker with the alias sideWidgets, and a new MNTP with the alias sideWidgets7. Both are set from a tab in the page's doctype. If I use this simple code from within the rendered file from the macro I call:

    if(Model.Content.HasValue("alias"))
    {
        <h1>true</h1>
    }
    else
    {
        <h1>false</h1>
    }
    

    Setting alias as sideWidgets resolves as true, but as sideWidgets7 it resolves false.

    Maybe I should mention that this isn't a site that I created, just one that I have inherited!

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 07, 2015 @ 12:16
    Dennis Aaen
    0

    Hi Paul,

    Perhaps it's the XML that is not updated with the new property. You could try go to umbraco.config it is located in the /App_Data folder, on your Umbraco file system. If the property isen´t there then try:

    Rright clicking the “CONTENT” root node in Umbraco and choose “Republish entire site”?

    This updates the /App_Data/umbraco.config cache. Did you remember to save and publish the page with the MNTP and it has an item, assigned to it just to be sure :).

    Maybe you could also do a IIS reset just in case. 

    Hope this helps.

    /Dennis

  • Paul 24 posts 114 karma points
    May 07, 2015 @ 12:20
    Paul
    0

    Thanks again Dennis, yes that's all it was, I republished the site and umbraco.config was updated with the changes! Always something simple!

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 07, 2015 @ 12:23
    Dennis Aaen
    0

    Hi Paul,

    You are welcome, it´s nice when small changes makes big differences right : -)

    Happy Umbraco coding, 

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft