DataSources which have [Configuration]
attributes can also support full visual configuration. The system looks for a content type with the same name as the DataSource + Configuration. In this case, it's looking for a Content Type WithConfigConfiguration
.
-
-
-
-
⬇️ Result | Source ➡️
Data in the Query (7)
-
Hello from WithConfig #1 - Favorite Color: burgundy
-
Hello from WithConfig #2 - Favorite Color: burgundy
-
Hello from WithConfig #3 - Favorite Color: burgundy
-
Hello from WithConfig #4 - Favorite Color: burgundy
-
Hello from WithConfig #5 - Favorite Color: burgundy
-
Hello from WithConfig #6 - Favorite Color: burgundy
-
Hello from WithConfig #7 - Favorite Color: burgundy
@inherits Custom.Hybrid.RazorTyped
@using ToSic.Razor.Blade
@using System.Linq
@using ToSic.Eav.DataSources
<h3>Data in the Query (@MyData.List.Count())</h3>
<ul>
@foreach (var item in AsItems(MyData)) {
<li>
<strong>@item.Get("Title")</strong> - Favorite Color: @item.Get("FavoriteColor")
</li>
}
</ul>
@* TODO:: @2dm Query Img *@
Source Code of WithConfig.cs
using System.Linq;
using ToSic.Eav.DataSource; // This namespace is for the [Configuration] attribute
public class WithConfig : Custom.DataSource.DataSource16
{
public WithConfig(MyServices services) : base(services, "My.Magic")
{
ProvideOut(() => {
var result = Enumerable.Range(1, AmountOfItems).Select(i => new {
Title = "Hello from WithConfig #" + i,
FavoriteColor,
});
return result;
});
}
// This attribute [Configuration] creates a configuration "FavoriteColor"
// In this example [Configuration] already knows about the fallback.
// * The property getter calls Configuration.GetThis()
// * GetThis() will automatically use the property name "FavoriteColor" to look up the config
// * Calling an empty GetThis() will always return a string,
// so it's ideal for string-properties where the Fallback was specified before
[Configuration(Fallback = "magenta")]
public string FavoriteColor { get { return Configuration.GetThis(); } }
// This attribute [Configuration] creates configuration "AmountOfItems"
// * The property getter calls Configuration.GetThis()
// * GetThis() will automatically use the property name "AmountOfItems" to look up the config
// and will use the default value of 1 if it was not specified
[Configuration]
public int AmountOfItems { get { return Configuration.GetThis(1); } }
}
View Configuration
This is how this view would be configured for this sample.
- Query: DynamicDataSourceWithConfig
Details for DynamicDataSourceWithConfig
Use Custom DataSources in Visual Query
Custom DataSources appear under App in Visual Query.