Data URLs in Static Data Types

Use specific attributes to use fields in data URLs

When creating static data types, you can also use supported fields in data URLs.

To do so, use the following attributes on fields:

  • [RouteSegment(Int order)] : Declares that the current field should appear in the data URL
  • [RouteDateSegment(Int order,  DateSegmentFormat format)] : Applicable for DateTime fields only. Declares that the current field should appear in the data URL in the specified format.

The order parameter indicate the position of the field in the data URL.

// ... some other code

[InternalUrl("pageFolder1")]
public interface PageFolder1 : IPageDataFolder
{
    // ... some other code

    [RouteSegment(1))]
    string MyStringField { get; set; }

    // ... some other code

    [RouteDateSegment(0, DateSegmentFormat.YearMonth)]
    DateTime MyDateTimeField { get; set; }
}

In the above example, the MyDateTimeField will be first to appear in the data URL. It will have the format of 'Year/Month'. The MyStringField will appear the second. This is the equivalent of the {MyDateTimeField}/{MyStringField} order.

In CMS Functions, you should use a parameter of the type RoutedData<T> to apply the default data URL format associated with the type. Here is the example for a C1 CMS Razor function:

@using Test
@inherits RazorFunction

@functions {
    [FunctionParameter]
    public RoutedData<PageFolder1> ViewModel { get; set; }
}

<html xmlns="http://www.w3.org/1999/xhtml" 
	  xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>

    @if (ViewModel.IsItem)
    {
        <h1>
            Id = @ViewModel.Item.Id
        </h1>
        <div>
            String = @ViewModel.Item.MyStringField
        </div>
        <div>
            Date = @ViewModel.Item.MyDateTimeField
        </div>

        <br />
        <a href="@ViewModel.ListUrl"> Back to list</a>
    }
    else
    {
        <h1> List of data items: </h1>

        foreach (var item in ViewModel.List)
        {
            <div>
                <a href="@ViewModel.ItemUrl(item)">
                    @item.MyStringField
                </a>
                <a href="~/pageFolder1(@item.Id)">
                    Dynamic link
                </a>
            </div>
        }
    }
</body>
</html>