title: How to make this Bootstrap Carousel into reusable Razor component to use in Blazor app
body: <p>I am building a razor component for use in a Blazor client-side app. I am wondering how i can make the images used in the component dynamic, and set the images in the page code-block where i call the component.</p>
  
  <p>Here is my Carousel.razor component</p>
  
  <pre><code>@inject IJSRuntime JsRuntime
  @namespace BlazorFrontend.Components
  
  &lt;div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"&gt;
      &lt;ol class="carousel-indicators"&gt;
          &lt;li data-target="#carouselExampleIndicators" data-slide-to="0"  class="active"&gt;&lt;/li&gt;
          &lt;li data-target="#carouselExampleIndicators" data-slide-to="1" &gt;&lt;/li&gt;
          &lt;li data-target="#carouselExampleIndicators" data-slide-to="2" &gt;&lt;/li&gt;
      &lt;/ol&gt;
      &lt;div class="carousel-inner"&gt;
          &lt;div class="carousel-item active"&gt;
              &lt;img class="d-block w-100" src="pictures/foo.jpg" alt="First slide"&gt;
          &lt;/div&gt;
          &lt;div class="carousel-item"&gt;
              &lt;img class="d-block w-100" src="pictures/bar.jpg" alt="Second slide"&gt;
          &lt;/div&gt;
          &lt;div class="carousel-item"&gt;
              &lt;img class="d-block w-100" src="pictures/foobar.jpg" alt="Third slide"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="carousel-control-prev" role="button" id="carouselExampleIndicators-prev" data-slide="prev"&gt;
          &lt;span class="carousel-control-prev-icon" aria-hidden="true"&gt;&lt;/span&gt;
          &lt;span class="sr-only"&gt;Previous&lt;/span&gt;
      &lt;/a&gt;
      &lt;a class="carousel-control-next" id="carouselExampleIndicators-next" role="button" data-slide="next"&gt;
          &lt;span class="carousel-control-next-icon" aria-hidden="true"&gt;&lt;/span&gt;
          &lt;span class="sr-only"&gt;Next&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  
  @code{
      protected override async Task OnInitializedAsync()
          {
              foreach (System.Collections.DictionaryEntry de in Environment.GetEnvironmentVariables())
              {
                  System.Console.WriteLine("ENVVAR: key=" + de.Key + " value=" + de.Value);
                  System.Console.WriteLine(Environment.GetEnvironmentVariable("ASSETS"));
              }
          }
          private string AssetsEndpoint = Environment.GetEnvironmentVariable("ASSETS");
          bool firstRender = true;
  
          protected async override Task OnAfterRenderAsync(bool firstRender)
          {
              if (firstRender)
              {
                  await JsRuntime.InvokeAsync&lt;object&gt;("initializeCarousel");
                  firstRender = false;
              }
          }
  }
  </code></pre>
  
  <p>Ideally, i would have liked to do something like this:</p>
  
  <pre><code>  &lt;img class="d-block w-100" src=@slide1 alt="First slide"&gt;
  
  code{
      string slide1;
  }
  </code></pre>
  
  <p>and in the code block of the page i am using the component in:</p>
  
  <pre><code>&lt;Carousel&gt;&lt;/Carousel&gt;
  
  code{
      slide1 = "pictures/foo.jpg"
  }
  </code></pre>
  
  <p>for example, but of course, that isn't going to work. What is the right/Blazor way of doing this?</p>