I'm with a customer that absolutely loves Nested Content, they've built everything with it. However they've asked me to customise the label templates.
They want me to display different titles according to different settings of different properties.
I was hoping to write a function in a similar way to archetype. I've good experience of doing that also caching the results to avoid that horrible performance hits you can get.
But everything I'm reading seems to say that there is currently no way this can be done. All the posts and threads seem to be quite old. So I'm hoping that maybe something has moved on with this? Or not.
You can do various stuff by checking for equality with empty string. For example, if you want to conditionally show a hyphen between the names of two picked nodes, then you can use:
{{ contentPicker1 !== '' ? '-' : '' }}
to prevent a weird name like " - " showing if the items haven't been picked yet.
So I guess for @John a possible solution would be:
The first will not show anything if contentPickerId hasn't been picked, and the second one will show the linkOverrideText only if the content hasn't been picked.
ZAC ! That is genius. Thank you.
It's too easy to forget this is just javascript even if it is with an angular twist
(if that's not too much of a mixed metaphor)
Essentially if one property has a value (which is a simple text string) then the label should use that [let's call it "overrideTitle"]. However if it doesn't then the other property ["linkPicker"] is converted from the node id into the title of the node and returned. That part is working thanks to Matt's code.
However I had imagined passing both as a parameter to the function so that the function could return whichever it should, however would this syntax above allow the overrideTitle to be conditionally returned if it has a value, and the linkPicker to be sent to the filter *
Function for Label Templates
I'm with a customer that absolutely loves Nested Content, they've built everything with it. However they've asked me to customise the label templates.
They want me to display different titles according to different settings of different properties.
I was hoping to write a function in a similar way to archetype. I've good experience of doing that also caching the results to avoid that horrible performance hits you can get.
But everything I'm reading seems to say that there is currently no way this can be done. All the posts and threads seem to be quite old. So I'm hoping that maybe something has moved on with this? Or not.
Is there any way this is possible?
Hi John,
See my reply on this thread... https://our.umbraco.org/projects/backoffice-extensions/nested-content/nested-content-feedback/81260-name-template-show-name-instead-of-id#comment-259762
Cheers,
- Lee
Thanks Lee - ok so I need to try and start by understanding what an Angular filter is, I'm sure I'll work it out!
Lee.... (said with slight whiny voice)
One further question:
So that's great and it's working and I can pass in a single property value.
However is there a way to pass in the whole object of property values? Or maybe more simply to pass in more than one property value?
Hi John,
Guess it depends what you're wanting to do with the values?
Instead of using the angular filters, you could use the object value itself, like...
If that makes sense?
Just to say that I'm no angular expert, I'm figuring things out as I go along ;-)
Cheers,
- Lee
sorry reading that again it wasn't clear what i mean't
included in the values that are set are a picked link, and a text string
if the text string is set, then that is used instead of the title of the picked content
so ideally I want to do something like
{{ [ contentPickerId,linkOverrideText ] | myFilter }}
where I have made up the syntax [ propertyValue1 . propertyValue2 ]
or {{ allthePropertyValuesAsAnArrayOrObject | myFilter }}
not sure which is better or possible if at all
Hmmm... I've never tried this, but could try doing a JS evaluation of the objects?
If that doesn't work, I'm not sure what other options there are.
I just tried something like this, and it does work. In fact, you seem to be able to write any normal javascript logic.
You can do various stuff by checking for equality with empty string. For example, if you want to conditionally show a hyphen between the names of two picked nodes, then you can use:
to prevent a weird name like " - " showing if the items haven't been picked yet.
So I guess for @John a possible solution would be:
The first will not show anything if
contentPickerId
hasn't been picked, and the second one will show thelinkOverrideText
only if the content hasn't been picked.ZAC ! That is genius. Thank you. It's too easy to forget this is just javascript even if it is with an angular twist (if that's not too much of a mixed metaphor)
Essentially if one property has a value (which is a simple text string) then the label should use that [let's call it "overrideTitle"]. However if it doesn't then the other property ["linkPicker"] is converted from the node id into the title of the node and returned. That part is working thanks to Matt's code.
However I had imagined passing both as a parameter to the function so that the function could return whichever it should, however would this syntax above allow the overrideTitle to be conditionally returned if it has a value, and the linkPicker to be sent to the filter *
* eh!? eh!? I'm learning the lingo! Filter right!? Eh? ;)
is working on a reply...