Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 40 posts 275 karma points
    May 09, 2019 @ 13:33
    Jesper SkjĂžnnemand
    0

    Umbraco v8 returns this when I use "insert value"

    @Model.Value("seoTitle")
    

    This works just fine, but I would like to use another value ("pageTitle") as a fallback.

    This works on a v7 site i made recently:

    @Umbraco.Field("seoTitle", altFieldAlias:"pageTitle")
    

    How would I do the same in v8? I can't seem to find any documentation on this, only about fallback to ancestor or language, which is not what I need here.

  • Marc Goodson 1675 posts 11026 karma points MVP 6x c-trib
    May 14, 2019 @ 21:56
    Marc Goodson
    101

    Hi Jesper

    It's possible but the syntax is different!

    try:

    Model.Value<string>("seoTitle", fallback: Fallback.ToDefaultValue, defaultValue: Model.Value<string>("pageTitle"))
    

    Essentially now Model.Value has three 'fallback' options if the alias of the property you are writing out is empty.

    It can fallback to default value - and the default value can be read from another property as above

    or you can Fallback.ToAncestors and read the same aliased property on a parent node going up through the content tree until a matching value is found

    or Fallback.ToLanguage if you are using variants, and a missing Swedish value should 'fallback' to English etc

    regards

    marc

Please Sign in or register to post replies

Write your reply to:

Draft