Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Feb 24, 2017 @ 16:12
    John C Scott
    1

    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?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 24, 2017 @ 16:14
  • John C Scott 473 posts 1183 karma points
    Feb 24, 2017 @ 16:17
    John C Scott
    1

    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!

  • John C Scott 473 posts 1183 karma points
    Feb 28, 2017 @ 15:21
    John C Scott
    1

    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?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 28, 2017 @ 15:54
    Lee Kelleher
    1

    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...

    {{properyAlias[0].something}}
    

    If that makes sense?

    Just to say that I'm no angular expert, I'm figuring things out as I go along ;-)

    Cheers,
    - Lee

  • John C Scott 473 posts 1183 karma points
    Feb 28, 2017 @ 15:59
    John C Scott
    0

    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

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 28, 2017 @ 16:08
    Lee Kelleher
    0

    Hmmm... I've never tried this, but could try doing a JS evaluation of the objects?

    {{ (propertyValue1 || propertyValue2) | myFilter }}
    

    If that doesn't work, I'm not sure what other options there are.

  • Zac 223 posts 575 karma points
    Mar 01, 2017 @ 14:32
    Zac
    1

    I just tried something like this, and it does work. In fact, you seem to be able to write any normal javascript logic.

    {{ (contentPicker1 !== '' ? contentPicker1 : contentPicker2) | ncNodeName }}
    

    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:

    {{ contentPickerId | myFilter }}{{ contentPickerId === '' ? linkOverrideText : '' }}
    

    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.

  • John C Scott 473 posts 1183 karma points
    Mar 02, 2017 @ 15:14
    John C Scott
    1

    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? ;)

Please Sign in or register to post replies

Write your reply to:

Draft