With the new Block List we can use a custom expression for label, e.g. "Block {{myPropertyAlias}}".
However it would be great if we could use basic angular expression like we can in Nested Content, e.g. "Block {{$index + 1}}".
This expression seems just to render "Block 1" for all blocks.
Seems like a great idea to me!
For reference Nested Content has this to get the name/label:
Hi @bjarnef,
We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.
For more information about issues and states, have a look at this blog post
Thanks muchly, from your friendly Umbraco GitHub bot :-)
@bjarnef you should be able to use angular expressions, but $index is not available, you can only choose values of your content properties(by their alias). If you think index is a missing option, I think it would be fairly simple to make that available as well. :-)
@nielslyngsoe yes I think this is a missing option :) It would be great this is a bit consistent with Nested Content name template. See the link getName function in Nested Content 馃檪
Additionally, @liquidkool is asking for the following feature:
I want to populate the label field with content from the settings tab. I can get content from the content tab using
{{aliasName}}, however this doesn't work with content from the settings tab. I've tried{{settings.aliasName}}. Not sure if its possible?
Adding support to access both data/content and settings would mean the existing expressions need to change from {{myPropertyAlias}} to something like {{content.myPropertyAlias}}, so you can access settings with the same alias using {{settings.myPropertyAlias}}.
I don't know what data the custom AngularJS views (for displaying previews within the back-office) have access to, but it would make a lot of sense to make the namings/models the same for the name template!
The block label is generated in getBlockLabel method here:
https://github.com/umbraco/Umbraco-CMS/blob/v8/8.7/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js#L102-L112
Where the config label is being interpolated here:
https://github.com/umbraco/Umbraco-CMS/blob/v8/8.7/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js#L556-L558
However in Nested Content it pass in the index. Not sure if it is possible the generate the index without passing in the index or retrieve this index by the position of the item in the array.
Furthermore in Nested Content when using $index it actually render $index + 1:
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js#L358
@nielslyngsoe not sure if the isolatedScope can be passed as the "scope" for the $interpolate call.
https://stackoverflow.com/a/39058278
e.g. here:
https://github.com/umbraco/Umbraco-CMS/blob/v8/8.7/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js#L556-L558
@nielslyngsoe do you know if we can do something to pass in $index to getBlockLabel similar to getName in Nested Content?
https://github.com/umbraco/Umbraco-CMS/blob/v8/8.7/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js#L108
@bjarnef so this is the line where the stuff happens. The object parsed here contains the variables available for the interpolation. So currently its just the content of 'data' that we have available, so if you like to make settings available you should make a new object, like:
var interpolateVars = Utilities.copy(blockObject.data);
interpolateVars.$settings = blockObject.settings; // edited to $settings as of ronaldbarendse comment.
interpolateVars.$index = block.index;//?
I would say we need to do it this way to stay backward compatible, I hope this helps and give some inspiration for how we can solve this one :-)
@nielslyngsoe I would change the name to $settings, so you don't get conflicts with data/content properties that have the same alias (as I described in https://github.com/umbraco/Umbraco-CMS/issues/8689#issuecomment-682480638). This will ensure it's backwards compatible, the syntax for accessing data/content is kept short (no prefixing with content.) and is similair to Nested Content 馃憤
@ronaldbarendse good point, I'm happy with that. Thanks for being aware :-)
Fixed in #9275
Due for release in 8.10.0