Question

Is it possible in HAML to create variable TAGs as the subject asks?

Want to do

- tag = "h1"


%tag

Cheers

Final Version I used was

-# Type Default
- if ! defined? locals[ :type ]
    - type = "h1"
- else
    - type = locals[ :type ]

-# Heading
- haml_tag type do

    -# Main Text
    = locals[:text]

    -# Add the secondary text if required
    -if defined? locals[ :small ]
        %small= locals[ :small ]
Was it helpful?

Solution

Yeah, it's possible.

Try this.

- tag = 'h1'
- haml_tag tag, "I'm h1."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top