Copied to clipboard

Flag this post as spam?

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


  • Yaco Zaragoza 88 posts 362 karma points
    May 12, 2023 @ 13:43
    Yaco Zaragoza
    0

    Links (explain documentation)

    I am using a Multi Url Picker (with a limit of 1 URL) with Modelsbuilder enabled

    and I am referencing the documentation here:

    https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/multi-url-picker

    but the only code that is showing is

    @using Umbraco.Cms.Core.PublishedCache;
    @inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
    @{
        // Set the value of the property with alias 'footerLinks'
        content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.FooterLinks).Alias, links);
    }
    

    with no context of how to use it.

    Is this example is Home referring to the Page Type? is FooterLinks the name of the property in the Home Page?

    Any feedback would be greatly appreciated

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    May 12, 2023 @ 21:57
    Marc Goodson
    100

    Hi Yaco

    That example is showing how to programmatically set a value in Umbraco for a MultiUrlPicker.

    Imagine if you were writing an import routine, to bring content from a legacy system, and make it editable via Umbraco.

    The legacy content might have a title an image some text and a link.

    You'd define a document type of a text, media picker, rte and a multi url picker.

    You use the ContentService, which is the gateway for CRUD actions with Umbraco content (warning: don't use it for rendering content, always use the published cache for that) to achieve this import.

    Each property is set by its alias.

    Each type of property needs the content to be provided in different formats depending on how the data is stored.

    The documentation is showing you how to set a MultiUrlPicker content programmatically with the ContentService

    The first example shows using the alias as a string "footerLinks" but some people don't like this approach, if the alias changed, or was mistyped, you Only find out at runtime, so the second example, is showing how, with modelsbuilder, youcan get ygat alias from the generated model, so if it ever changed, the project wouldn't build, and you'd find the potential problem before deploying!

    Regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft