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?
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
};
});
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}}
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].
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}}
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?
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#L10I would also be ideal to add a prefix to avoid collision with core or other packages:
For example:
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}}
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:
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 theprefix
part in the name, but notumb
orcms
.Which expression do you ue in the Nested Content template?
Actually I think it need to be something like this:
Cell {{$index | somePrefixMyCustomFilter}}
is working on a reply...