I ran into this recently, and considered three options to avoid duplicating the Asset Listing without resorting to client side JS.
1. SSJS
Use the listing to collect an array of AssetIDs, then iterate over it twice.
Default Format
<script runat="server">
items.push("%asset_assetid%")
</script>
Page Contents
<script runat="server">
var items = [];
</script>
%asset_listing%
<ul>
<script runat="server">
items.forEach(function(e) {
print("<li>%globals_asset_name:" + e + "%</li>")
})
</script>
</ul>
<ul>
<script runat="server">
items.forEach(function(e) {
print("<h2>%globals_asset_name:" + e + "%</h2>")
print("<h2>%globals_asset_contents_raw:" + e + "%</h2>")
})
</script>
</ul>
2. Flexbox order
Use the order
CSS property with flexbox to render the contents in a different order to the markup.
Default Format
<div class="list1">%asset_name%</div>
<div class="list2">
<h2>%asset_name%</h2>
%asset_contents_raw%
</div>
Page Contents
<style>
.list1 {
background: lemonchiffon;
order:1;
}
.list2 {
background: lavender;
order:2;
}
.container {
display:flex;
flex-direction: column;
}
</style>
<div class="container">
%asset_listing%
</div>
3. Conditional keyword to print two versions of the same listing
Set up the listing to take a parameter to control which version it prints, then include the asset listing twice
Default Format
%begin_nested_get_variant^eq:2%
<div class="list2">
<h2>%asset_name%</h2>
%asset_contents_raw%
</div>
%else_nested%
<div class="list1">%asset_name%</div>
%end_nested%
A page somewhere you want to embed the double listing
%globals_asset_contents_raw:786%
%globals_asset_contents_raw:786^with_get:variant=2%
Personally I prefer #3 - the flexbox order thing is a bit hackish, and really ties your hands on what you can do with the markup. The SSJS is the most obvious, but it’s a shame to have to do all your markup inside a print()
statement and worrying about string escaping etc.