AsAdam(...) Command
Note
ADAM is the Automatic Digital Asset Manager. It manages files (Assets) for content in 2sxc.
The files are managed so that they really belong to the item they are used in.
Read more about ADAM
When a content-item has a Library
field (see Field Input-Type hyperlink-library) your code needs to get a list of all the files and folders of that field. For example to show galleries.
This is where AsAdam(...)
comes in. It gives you the ADAM parts of this field.
⚡ The official API docs.
Basically all you need for AsAdam(...)
is
- The Content Item (Entity or DynamicEntity)
- The field name of which you want the Adam objects
As a result you'll get an IFolder object with which you can get all files in the folder or subfolders.
We have an rich series of Razor tutorials. You should really check them out 👍.
Example
This example is taken from the Fancybox Gallery App
@inherits Custom.Hybrid.Razor12
@using ToSic.Razor.Blade;
@using Dynlist = System.Collections.Generic.IEnumerable<dynamic>;
<div class="ga-wrapper">
<div class="ga-albums row">
@foreach (var album in AsList(Data)) {
var images = AsAdam(album, "Images").Files as Dynlist;
var albumThumbUrl = Text.Has(album.AlbumThumbnail)
? album.AlbumThumbnail
: images.First().Url;
<div class="ga-album col-12 col-sm-6 col-md-6 col-lg-4" @Edit.TagToolbar(album)>
<a href='@Tags.SafeUrl(Link.To(parameters: "mid/" + Dnn.Module.ModuleID + "&album=" + album.Path))'>
<div class="ga-img">
<div class="overlay">
<div class="ga-album-title"><h5 class="ga-title">@album.Title</h5></div>
<div class="ga-files-count"><span class="badge badge-pill badge-dark float-end">@images.Count()</span></div>
</div>
<img class="img-fluid" src='@Tags.SafeUrl(albumThumbUrl + "?w=720&h=500&mode=crop&scale=both&quality=80")' alt="@album.Title" />
</div>
</a>
</div>
}
</div>
</div>
We suggest you check out some apps which use ADAM to see how they work.
Also Read
- ADAM - Automatic Digital Asset Management
- ToSic.Sxc.Adam
- check out
AsAdam(...)
in the RazorComponent and ApiController
History
- General Tokens introduced in 2sxc 8.0
- Added extra security switch in 2sxc 9.32