Copied to clipboard

Flag this post as spam?

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


  • Joseph 59 posts 140 karma points
    Jan 08, 2015 @ 04:50
    Joseph
    0

    Using a multi-content picker as a macro parameter

    Hello

    One issue that comes up from time to time is the need to add a MNTP-like data type as a macro parameter. Somewhat surprisingly to me, there isn't yet a solution for this out there (or I couldn't find one) - I would have thought that this would be a fairly common problem for people. I have frequently worked around this by using multiple content pickers instead (which is limited and very inelegant) - I was wondering however if there was a better solution for this and/or if there was a Umbraco HQ endorsed solution for this problem?

    cheers Joseph

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 08, 2015 @ 05:32
    Jan Skovgaard
    101

    Hi Joseph

    If you're using Umbraco 7 then you should be able to turn any property editor into a macro parameter. It's described how to do it in the angular workbook for Umbraco here https://github.com/umbraco/AngularWorkbook/blob/master/Exercises/Exercise10.md - If you have not gotten any experience with AngularJs yet then I suggest you work through the entire book.

    Hope this helps.

    /Jan

  • Jason Espin 368 posts 1335 karma points
    Apr 21, 2016 @ 11:21
    Jason Espin
    0

    This isn't necessarily true. Half the time you will experience errors such as $scope.model.config is null because the documentation states all you need to do is add a single line when most of the time that is not the case. Like now, I'm trying to create a multiple content picker from scratch that can be used as a macro parameter, because this functionality does not (and should) exist in the core, and all i'm getting is this annoying stupid error all the time that the angular workbook doesn't even mention!

  • Joseph 59 posts 140 karma points
    Jan 08, 2015 @ 22:07
    Joseph
    0

    Thanks for that angular workbook! I have been looking for something similar to get me going on Umbraco 7!

    For Umbraco 6 (and below) solutions however - do you have any recommendations around a multi-content picker macro parameter?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 08, 2015 @ 22:15
    Jan Skovgaard
    1

    Hi Joseph

    You're very welcome :)

    Hmm, I don't know other information about how to do it in older versions than what Richard writes about here http://www.richardsoeteman.net/2010/01/04/CreateACustomMacroParameterType.aspx - But be aware that this is very old information since the post is from 2010 and A LOT has happened since.

    I can imagine that the methods etc. displayed in there are deprecated / obsolete - But perhaps there a newer methods etc. available, which can make you achieve the same.

    Hope this helps.

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 08, 2015 @ 22:18
    Dennis Aaen
    0

    Hi Joseph,

    For Umbraco 6, you could try to see the documentation, http://our.umbraco.org/Documentation/Extending-Umbraco/Macro-Parameter-Editors/ and this old post from Richard Soeteman http://www.richardsoeteman.net/2010/01/04/CreateACustomMacroParameterType.aspx

    Hope this helps,

    /Dennis

  • Joseph 59 posts 140 karma points
    Jan 08, 2015 @ 22:31
    Joseph
    0

    Thanks all!

  • Joseph 59 posts 140 karma points
    Jan 21, 2015 @ 03:58
    Joseph
    0

    Hello

    I've made a start on trying to get this to work on Umbraco 7. Here's what I've done so far:

    1. Tracked down the html file that's related to the MNTP (found it here: \umbraco\views\propertyeditors\contentpicker\contentpicker.html)
    2. Tracked down the related Javascript (I extracted contentPickerController from \umbraco\Js\umbraco.controllers.js)
    3. Added these to my manifest in App_Plugins as follows:

      {
          alias: "ContentPickerDataType",
          name: "Multi Content Picker",
          isParameterEditor: true,
          editor: {
              view: "~/App_Plugins/MacroDataTypes/contentpicker.html"
          }
      

      }

    and

    javascript: [
        ...
        "~/App_Plugins/MacroDataTypes/contentpicker.controller.js"
    ]
    

    where contentpicker.html and contentpicker.controller.js are extracted from (1) and (2).

    The good news is that this doesn't seem to have broken anything and indeed, it appears correctly now as a macro parameter when added to my macros. It doesn't actually work however - I get a whole bunch of JS errors in the console so something's not set up correctly or potentially something is missing.

    Am I on the right track here?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 21, 2015 @ 05:19
    Jan Skovgaard
    0

    Hi Joseph

    Have you set the "Debug" attribute in your web.config file to true? If not do that and the make sure to clear your browser cache and then recycle the app pool and then you should be good to go. If not then please post the errors from the browser console log.

    Cheers, Jan

  • Joseph 59 posts 140 karma points
    Jan 21, 2015 @ 20:46
    Joseph
    0

    Debug attribute, etc are all set. Here's the error:

    TypeError: Cannot read property 'multiPicker' of null
        at new contentPickerController (http://localhost:7180/App_Plugins/MacroDataTypes/contentpicker.controller.js:63:59)
        at d (http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:28:304)
        at Object.instantiate (http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:28:434)
        at http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:53:326
        at http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:44:274
        at n (http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:7:74)
        at k (http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:44:139)
        at e (http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:40:139)
        at http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:39:205
        at http://localhost:7180/umbraco/lib/angular/1.1.5/angular.min.js:158:18
    

    It looks like something's not initialised properly?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 21, 2015 @ 20:53
    Jan Skovgaard
    0

    Hi Joseph

    What does the content of your view look like?

    /Jan

  • Joseph 59 posts 140 karma points
    Jan 21, 2015 @ 20:59
    Joseph
    0

    Exactly the same as shipped with Umbraco:

    <div ng-controller="Umbraco.PropertyEditors.ContentPickerController" class="umb-editor umb-contentpicker">
    
        <ng-form name="contentPickerForm">
    
            <ul class="unstyled list-icons" 
                ui-sortable
                ng-model="renderModel">
    
                <li ng-repeat="node in renderModel">
    
                    <i class="icon icon-navigation handle"></i>
    
                    <a href="#" prevent-default ng-click="remove($index)">
                        <i class="icon icon-delete red hover-show"></i>
                        <i class="{{node.icon}} hover-hide"></i> 
                        {{node.name}}
                    </a>
                    <div ng-if="!dialogEditor && model.config.showEditButton">
                        <small><a href umb-launch-mini-editor="node">Edit</a></small>
                    </div>
                </li>
            </ul>
    
            <ul class="unstyled list-icons" ng-show="model.config.multiPicker === true || renderModel.length === 0">
                <li>
                    <i class="icon icon-add blue"></i>
                    <a href="#" ng-click="openContentPicker()" prevent-default>
                        <localize key="general_add">Add</localize>
                    </a>
                </li>
            </ul>
    
            <!--These are here because we need ng-form fields to validate against-->
            <input type="hidden" name="minCount" ng-model="renderModel" />
            <input type="hidden" name="maxCount" ng-model="renderModel" />
    
            <div class="help-inline" val-msg-for="minCount" val-toggle-msg="minCount">
                You need to add at least {{model.config.minNumber}} items
            </div>
    
            <div class="help-inline" val-msg-for="maxCount" val-toggle-msg="maxCount">
                You can only have {{model.config.maxNumber}} items selected
            </div>
    
    
        </ng-form>
    </div>
    
  • Thomas Beckert 193 posts 469 karma points
    Jan 22, 2015 @ 12:23
    Thomas Beckert
    2

    Hi,

    I'm just looking for the solution to pick up several ContentNodes as Macro Parameter and found these posts here.

    Is there any progress? I don't understand why this basic functionality isn't implemented in the core. As far as I know, it was possible in V6.

    Anyway, if anyone has a solution for this, could she / he provide a package?
    Is there anything I can do to support this issue?

     

    Best regards -

     

    Tom

  • Thomas Beckert 193 posts 469 karma points
    Jan 22, 2015 @ 12:58
    Thomas Beckert
    0

    Hi there, found a solution.

    This code here works:

    https://gist.github.com/westfall/22dc3fe56a27f816ba0b/download#

    In my partial view, I call:

    <p>@Model.MacroParameters["Links"].ToString()</p>

    And I get sort of this:

    [{id:nodeId, name:nodeName}, ....]

     

    If a package is needed, let me know.

  • Joseph 59 posts 140 karma points
    Jan 23, 2015 @ 04:01
    Joseph
    0

    Great find Thomas!

  • Tommy Enger 72 posts 277 karma points c-trib
    Mar 13, 2015 @ 09:09
    Tommy Enger
    0

    Hi Thomas. I get the picker to work 75%. I can pick items and retrieve them from code. But when I edit the macro it doesn't seem to render the picks, and it gives a blank list every time. Do you get the same?

  • Thomas Beckert 193 posts 469 karma points
    Mar 13, 2015 @ 09:35
    Thomas Beckert
    0

    With me it works. But I know that the umbraco backend has a very hard caching. Tried it in another browser?

  • Tommy Enger 72 posts 277 karma points c-trib
    Mar 13, 2015 @ 12:51
    Tommy Enger
    0

    Can't get it to work here. Instead I continued down Josephs track by extracting code from \umbraco\views\propertyeditors\contentpicker\contentpicker.html and \umbraco\Js\umbraco.controllers.js.

    I moved more of the properties into the defaultConfig property, when I got the same error as Joseph mentioned. I also removed all validation regarding minNumber and maxNumber because it caused some errors and I do not need it.

    My source code can be found here https://db.tt/v5bbQXsF (Still needs more testing)

    Can be used from the view like this (would not do it like this, but you get the idea)

    @{
        var contentIds = Model.MacroParameters["macroParameterAlias"] as string;
        var contentIdList = contentIds != null ? contentIds.Split(',').Select(int.Parse) : new int[0];
        var contentList = contentIdList.Select(id => Umbraco.TypedContent(id)).Where(c => c != null);
    }
    
    <ul>
        @foreach (var content in contentList)
        {
            <li><a href="@content.Url">@content.Name</a></li>
        }
    </ul>
    
  • Jason Espin 368 posts 1335 karma points
    Apr 21, 2016 @ 11:38
    Jason Espin
    0

    Heroes don't always wear capes. In this case Tommy Enger for a solution that uses Umbraco 7.2.4, this code has saved my bacon. I thankyou sir. Hopefully now someone will sort out this frankly embarassing mess and finally add this to the core!

  • Tommy Enger 72 posts 277 karma points c-trib
    May 04, 2016 @ 10:34
    Tommy Enger
    0

    Glad to help out. I have just added this and 2 more macro parameters to github: https://github.com/engern/Umbraco-custom-macro-parameters

  • Thomas Egebrand Gram 63 posts 138 karma points
    Feb 25, 2016 @ 11:45
    Thomas Egebrand Gram
    0

    Howdy!

    I've just run into this issue as well. Did anyone ever find a lasting solution? The above mentioned doesn't seem to work for me on v7.4.1.

    Also - any clue as to why this isn't included in the core? Seems like a pretty common usecase.

  • Jason Espin 368 posts 1335 karma points
    Apr 21, 2016 @ 11:28
    Jason Espin
    0

    Hi all,

    I'm having exactly the same problem. I cannot reiterate how much this SHOULD BE IN THE CORE!

    For me, the solution Thomas provides above doesn't seem to reload the values either when I edit.

    Anyone made any progress at all with this?

  • Pedro Adão 43 posts 80 karma points
    Sep 06, 2016 @ 10:01
    Pedro Adão
    0

    Same problem in v 7.5.2 :(

  • Pedro Adão 43 posts 80 karma points
    Sep 06, 2016 @ 10:10
    Pedro Adão
    0

    I had the same problem in 7.5.2 if its MANDATORY.

    :/

  • Tommy Enger 72 posts 277 karma points c-trib
    Sep 06, 2016 @ 10:42
  • Pedro Adão 43 posts 80 karma points
    Sep 06, 2016 @ 11:18
    Pedro Adão
    0

    Hi Tommy Enger,

    Thanks for the reply.

    Its working now but i didn't change any code. Just unchecked the mandatory option. saved. tested and its ok. marked again as mandatory and works. can't reproduce the bug. :(

    CACHE?

Please Sign in or register to post replies

Write your reply to:

Draft