Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic element in jade mixin

I'd like to create a button mixin in Jade. However I dont know on which html elements I'll apply those mixin, e.g. a, button or input.

My question: is it possible to choose the element from a mixin? e.g. calling it like this a+button or input+button

or using a element parameter to insert the element with the mixin

mixin button(element, style, size, expand, fill, round, simple)
    - var style = (typeof href === 'undefined') ? '' : style
    - var fill = (typeof fill === 'undefined') ? '' : 'btn-fill'
    - var expand = (typeof expand === 'undefined') ? '' : 'btn-block'
    - var round = (typeof round === 'undefined') ? '' : 'btn-round'
    - var simple = (typeof simple === 'undefined') ? '' : 'btn-simple'
    case size
        when "large"
            - size = "btn-lg"
        when "small"
            - size = "btn-sm"
        when "mini"
            - size = "btn-xs"
    element(href=href, role='button',class=["btn", "btn-" + style, size, fill, expand, round, simple])&attributes(attributes)
        block

Greetings

like image 374
user2030592 Avatar asked Nov 20 '25 23:11

user2030592


1 Answers

Found out by myself:

#{element} solves the problem
like image 171
user2030592 Avatar answered Nov 24 '25 08:11

user2030592



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!