Copied to clipboard

Flag this post as spam?

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


  • Vyacheslav 13 posts 113 karma points
    Nov 08, 2021 @ 14:05
    Vyacheslav
    0

    Nested Content, $Index in a template by alphabet.

    I want to see templates result like "Cell A", "Cell B", "Cell C" etc.
    Now result of template "Cell {{$index}}" is "Cell 1", "Cell 2".
    Is it possible to switch variable $index from number to letter?

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Nov 08, 2021 @ 14:34
    Bjarne Fyrstenborg
    1

    You would probably need to add a custom Angular filter and then use this in the template passing in $index as value to the filter. https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/src/Umbraco.Web.UI.Client/src/common/filters/nestedcontent.filter.js#L10

    I would also be ideal to add a prefix to avoid collision with core or other packages:

    For example:

    angular.module("umbraco.filters").filter("somePrefixMyCustomFilter", function () {
    
        // the alphabet    
        const alphabet['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    
        // get the index and return the letter of the alphabet
        function getLetter = function(index) {    
           return alphabet[index];
        }
    
        return function(input) {
             // Do something
        };
    
    });
    

    https://stackoverflow.com/a/30059213/1693918

    Maybe also set a limit in the Nested Content configuration to avoid more cells than characters in the alphabet depending on the culture or just a generic A-Z range of letters.

    And then something like this in the template: Cell {{somePrefixMyCustomFilter:$index}}

  • Vyacheslav 13 posts 113 karma points
    Nov 08, 2021 @ 15:48
    Vyacheslav
    0

    Thank you for your answer!
    This solution looks pretty clear.
    But can I use filters in Umbraco 8?

    I added this filter to my project, but I have this error:

    [$parse:syntax] Syntax Error: Token ':' is an unexpected token at column 26 of the expression [prefixGetLetterByIndexFilter:$index] starting at [:$index].
    
  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Nov 08, 2021 @ 16:36
    Bjarne Fyrstenborg
    0

    Yes, the UI part in backoffice in V9 hasn't changed much from V8 and should be pretty much the same.

    I guess the name of your angular filter is prefixGetLetterByIndexFilter. I would probably use a project name or company name instead of the prefix part in the name, but not umb or cms.

    Which expression do you ue in the Nested Content template?

    Actually I think it need to be something like this: Cell {{$index | somePrefixMyCustomFilter}}

Please Sign in or register to post replies

Write your reply to:

Draft