Copied to clipboard

Flag this post as spam?

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


  • Carsten A Pedersen 5 posts 75 karma points
    May 01, 2019 @ 16:50
    Carsten A Pedersen
    0

    Article items not showing image

    Hi there, I am a neewbie to Umbraco and have run into a problem.

    When trying to setup my "articles main" template under "settings" I have this code that should render out both text and image.

    However it does not render image, only the text from the other fields.

    Could anyone help?

    I have this code:

    @{ var selection = Umbraco.Content(Guid.Parse("e7977742-a161-4fdb-a579-415d705b4d25")) .Children("articleItem") .Where(x => x.IsVisible()); }

    @foreach (var item in selection)
    {
    
        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
            <div class="box london">
                <div class="box-icon">
                    <img src="@item.Value("articleImage770390")" alt="@Model.Value("articleImage770390")" class="img-responsive">
                </div>
        <div class="info float-container">
            <div class="col-sm-12 london-title">
                @item.Value("articleTitle")
            </div>
            <!-- Her kommer truncated indhold -->
                @Html.Raw(item.Value("articleContent").ToString().Truncate(100))
            <div class="col-sm-12 location-main">
                <hr> 
                <!-- her kommer knap og dato -->
                @item.Value("articleBtnDate")
            </div>
        </div>
    </div>
    

    Thanks in advance //Carsten

  • Lewis Smith 211 posts 620 karma points c-trib
    May 01, 2019 @ 17:19
    Lewis Smith
    0

    Hi Carsten,

    Looks like the image url is being output as it’s IPublishedContent form, give

    @item.Value("articleImage770390").Url

    A try?

    Lewis

  • Sowndar M 54 posts 148 karma points
    May 07, 2019 @ 06:16
    Sowndar M
    0

    Use the below code it will work

      @foreach (var item in selection)
        {
    
        var sectionImage = item.Value<IPublishedContent>("articleImage770390");
    
         @if (sectionImage != null)
         {
    <img class="img-fluid" src="@sectionImage.Url" alt="@sectionImage.Name" />
    }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft