Skip to main content

Razor Blade Tutorials

Tutorial HomeRazor.Blade

RazorBlade Fluent Tag API @Tag.Picture() with many sources v3

picture tags are the future of img tags. But it can be messy to create them, so here goes 😉. This example will return a small image if your screen is small, a large one otherwise. Try resizing the width of your browser to test. The image will become blurry if the browser is less than 800px wide.

RazorBlade API Docs

<picture><source srcset='/Portals/tutorials/2sxc/Tutorial-Razor/blade/assets/tag-img/%C3%BCberschrift-large.png' media='(min-width: 800px)'><img src='/Portals/tutorials/2sxc/Tutorial-Razor/blade/assets/tag-img/%C3%BCberschrift-small.png'></picture>

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials.

@inherits ToSic.Sxc.Dnn.RazorComponent
@using ToSic.Razor.Blade;
<!-- unimportant stuff, hidden -->
RazorBlade Fluent Tag API... <!-- unimportant stuff, hidden -->
  var path = App.Path + "/blade/assets/tag-img/";
  var small = "überschrift-small.png";
  var large = "überschrift-large.png";
  Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
  Tag.Img().Src(path + small)
<!-- unimportant stuff, hidden -->