Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alessandro Giuliano 6 posts 76 karma points
    Mar 27, 2019 @ 15:04
    Alessandro Giuliano
    0

    Hello everybody, I'm running umbraco 7.3 on several websites, now I need to add the alt text for every image since the previous developer build these templates without alt text and left me with this accessibility problems.

    I took my time to search in the forum but didn't find any working solution for my case.

    So I created an image property altText as a string in the media setting section.

    Then I have a template file with this section for the slideshow

    @if(CurrentPage.HasValue("lwStarterCartellaSlideshow"))
    {
        var classe="active";
        var conta=0;
      <div id="carousel-top" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
          @foreach(var item in Umbraco.TypedMedia(Int32.Parse(CurrentPage.GetPropertyValue("lwStarterCartellaSlideshow").ToString())).Children)
          {
          <li data-target="#carousel-top" data-slide-to="@conta" class="@classe"></li>
            if(classe=="active")
            {
             classe="";
            }   
            conta=conta+1;
          }
        </ol>
        <div class="carousel-inner" role="listbox">
        @{
            classe="active";
        }
          @foreach(var item in Umbraco.TypedMedia(Int32.Parse(CurrentPage.GetPropertyValue("lwStarterCartellaSlideshow").ToString())).Children)
          {
          <div class="item @classe">
            <img src="@item.Url" alt="">
          </div>
            if(classe=="active")
            {
             classe="";
            }   
          }
        </div>
        <a class="left carousel-control" href="#carousel-top" role="button" data-slide="prev">
          <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#carousel-top" role="button" data-slide="next">
          <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>    
    }
    

    I tried

    alt="@item.GetPropertyValue("altText")"
    

    But I only get a runtime error from the server

    any help would be appreciated, sorry for bad english

    Alessandro

  • Marc Goodson 876 posts 5710 karma points MVP 4x c-trib
    Mar 30, 2019 @ 14:28
    Marc Goodson
    1

    Hi Alessandro

    I'm wondering if this would work for you...

          @foreach(var item in Umbraco.TypedMedia(CurrentPage.GetPropertyValue<string>("lwStarterCartellaSlideshow")).Children)
          {
    var altText = item.HasProperty("altText") && item.HasValue("altText") ? item.GetPropertyValue<string>("altText") : item.Name;
          <div class="item @classe">
            <img src="@item.Url" alt="@altText">
    

    Essentially when you call 'Children' on a Media folder it retrieves the images beneath using the 'Examine' index - but if you've only just added the altText property to the MediaType, that won't immediately make it available in the index. I imagine if you visit each carousel image in the backoffice and re-save it, then the altText property will become available to display..., but also if you rewrite as above, if the property doesn't exist yet it won't error! - and infact it will default to be the name of the media item - which also might be a reasonable altText fallback and is guaranteed to be populated!

    regards

    Marc

  • Alessandro Giuliano 6 posts 76 karma points
    Apr 10, 2019 @ 08:45
    Alessandro Giuliano
    0

    Unfortunately this solution trigger a "/ server error" as well ://

  • Alessandro Giuliano 6 posts 76 karma points
    Apr 01, 2019 @ 09:54
    Alessandro Giuliano
    0

    Hi Marc,

    I'll try your code, I understand your point, honestly not being a developer but just a webdesigner I really appreciate your help

  • Jonas Nikolajsen 17 posts 103 karma points
    Apr 02, 2019 @ 11:38
    Jonas Nikolajsen
    0

    Hello have you tried ? :)

    alt="@(item.GetPropertyValue<string>("altText"))"
    
  • Alessandro Giuliano 6 posts 76 karma points
    Apr 10, 2019 @ 08:39
    Alessandro Giuliano
    0

    This solution trigger a "/ server error"

  • Ali Kazai 7 posts 77 karma points
    Apr 10, 2019 @ 10:57
  • Alessandro Giuliano 6 posts 76 karma points
    Apr 10, 2019 @ 16:40
    Alessandro Giuliano
    0

    you mean this?

    enter image description here

  • Alessandro Giuliano 6 posts 76 karma points
    Apr 17, 2019 @ 09:30
    Alessandro Giuliano
    0

    no solution for this? :/

Please Sign in or register to post replies

Write your reply to:

Draft