Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:28:36+00:00 2026-06-08T21:28:36+00:00

It’s my first try using the @if control directive from SASS . I have

  • 0

It’s my first try using the @if control directive from SASS.

I have a list of optimized images in a folder. Some of them are smaller as JPGs and others are smaller as PNGs.

With the @if rule I’m trying to say "if a JPG of that file exists use this @include, else use the other one."

(The gif’s in the example are there to clarify whether the "else if" part is right.)

My Example:

$list: A, B, C;

$type: jpg;

@mixin portfolio-images {
    @each $item in $list {
        a[href*="#{$item}"] span {

            /* @if starts */   

            @if $type == jpg {@include background-image-retina("#{$item}.jpg");}
            @else if $type == png {@include background-image-retina("#{$item}.png");}
            @else {@include background-image-retina("#{$item}.gif");}

            /* @if ends */   


            @include hide-text;
            width: 300px;
            height: 150px;
        }
    }
}

The JPGs display fine, but the PNGs don’t display at all – no output is compiled in the CSS file.

I use the @include background-image-retina and can’t define a custom variable for image type like in this fabulous mixin. So I’m not sure how to approach this.


Update: Like @lnrbob pointed out – it is not possible to check for existence of files with SASS. I marked his answer as correct since he provided an excellent @if example and in the long run helped me with this in understanding this SASS feature.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:28:37+00:00Added an answer on June 8, 2026 at 9:28 pm

    I’m confused what you are doing here. SASS won’t check your file system to see if A.jpg or ‘A.png` exists. You need to update the variable. So in your example (I think) it should look like this:

    $list: A, B, C;
    
    @mixin portfolio-images($type: 'jpg') {
        @each $item in $list {
            a[href*="#{$item}"] span {
    
                /* @if starts */   
    
                @if $type == jpg {@include background-image-retina("#{$item}.jpg");}
                @else if $type == png {@include background-image-retina("#{$item}.png");}
                @else {@include background-image-retina("#{$item}.gif");}
    
                /* @if ends */   
    
    
                @include hide-text;
                width: 300px;
                height: 150px;
            }
        }
    }
    

    And you’d use it like:

    @include portfolio-images('png');
    

    I don’t think this is what you are wanting to achieve though is it? If you are wanting to replicate the functionality of the retina-compass helper (which you’ve linked to as @include background-image-retina) you need to do this as some ruby script to feed into the compiling process that SASS uses (in this example the helper uses Compass).

    I hope this is, at least, mildly helpful. Please let me know if I’ve completely misunderstood and I’ll review 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.