0

Using stylus I want to create a mixin that uses the right image based on a locale option.

mixin

    locale-image(name, locale)
      if locale is not defined
         locale = 'en-US'
      background-image url('../images/'locale'/'name'.jpg')

Example Usage:

.us-image
    locale-image('my-us-image')

.ge-image
    locale-image('my-german-image', 'de-DE')

Basically is there a way to leave off a parameter like in the US example? How can I modify my mixin to support this?

1 Answer 1

5

Yep, you can use argument defaults:

  locale-image(name, locale = 'en-US')
    background-image url('../images/' + locale + '/' + name + '.jpg')

  .us-image
    locale-image('my-us-image')

  .ge-image
    locale-image('my-german-image', 'de-DE')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.