Copied to clipboard

Flag this post as spam?

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


  • Gary 80 posts 377 karma points
    Jul 20, 2016 @ 09:37
    Gary
    0

    Having a default image for an image cropper if the user doesnt submit image

    I am using an image cropper for news thumbnails on my website but i want to provide a default image if the user doesn't have a suitable image for the particular news article.

    I tried an if statement checking if the image cropper is null but it didn't work.

    Any help would be great.

    Kind Regards,

    Gary

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 20, 2016 @ 10:42
    Jan Skovgaard
    0

    Hi Gary

    What did the code you're trying to use look like? And what happened? Did you get an error or?

    You're on the right track but perhaps you hit a syntax error or your check never does anything etc. - So please share the code you tried to get working and let's take it from there :)

    /Jan

  • Gary 80 posts 377 karma points
    Jul 20, 2016 @ 11:57
    Gary
    0
    @if (@item.GetCropUrl("articleThumbnail", "thumbnail") == null){
                                <img src=" /media/1040/untitled-8.jpg">
                                } else {
                                <img src="@item.GetCropUrl("articleThumbnail", "thumbnail")"  alt="...">                                
                                }
    

    This uses the static image in the else statement. Can you see where im going wrong? Any help would be appreciated.

    Kind Regards,

    Gary

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 21, 2016 @ 04:49
    Jan Skovgaard
    0

    Hi Gary

    Ok, so I'm wondering if the thumbnail crop does not exist whether you're actually getting null back or whether the value is perhaps just empty.

    What do you get if you try to just render? Does it return a value or does it result in an error message?

    @item.GetCropUrl("articleThumbnail", "thumbnail")
    

    /Jan

  • Gary 80 posts 377 karma points
    Jul 21, 2016 @ 13:52
    Gary
    0

    Hi Again Jan,

    @item.GetCropUrl("articleThumbnail", "thumbnail")
    

    Returns This for one of the items:

    /media/725/volunteers.png?crop=0.42552469889322919,0,0.074475301106770836,0&cropmode=percentage&width=500&height=250&rnd=131129695810000000
    

    so there is a value. Is there a better way to check the value or existence of an image inside the image cropper?

    Cheers,

    Gary

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 22, 2016 @ 05:40
    Jan Skovgaard
    1

    Hi Gary

    When you write it returns a value for one of the items I'm getting a bit confused - What does it return for other items? We're not interested in those that have an image - Those that don't do we want to know what they return if anything like "Null" or just an empty string.

    The null check you do in your code currently obviously does not work so perhaps you need to check for both null and empty strings for instance :)

    /Jan

  • Gary 80 posts 377 karma points
    Jul 25, 2016 @ 10:13
    Gary
    102

    I have the answer..

    @if (@item.GetCropUrl("articleThumbnail", "thumbnail") != ""){
                                    <img src="@item.GetCropUrl("articleThumbnail", "thumbnail")"  alt="...">
                                    } else {
                                    <img src="http://safetycentre.manchesterfire.gov.uk/media/1040/untitled-8.jpg" alt="">      
                                    }
    

    Gives me exactly what i want.

    Thank you for your patience with this and your help :) !

    Kind Regards,

    Gary

Please Sign in or register to post replies

Write your reply to:

Draft