Create a local variable in Haml only

China☆狼群 提交于 2019-12-03 14:38:52

问题


I'm using Haml as a quick way of prototyping layouts. This is not using Rails, Sinatra or any framework.

What I want to do is declare a variable at the top and be able to call it throughout the page, similar to the way I can declare a variable in Sass and use it throughout the code.

!!! 5
  %body
    / Declare Variable
    - $type = 'Audio'

    .container{:id => "page-#{$type}"}

Is this possible?


回答1:


Drop the $ to avoid declaring a global variable. It should work just fine.

!!! 5
  %body
    / Declare Variable
    - type = 'Audio'
    .container{:id => "page-#{type}"}


来源:https://stackoverflow.com/questions/12430993/create-a-local-variable-in-haml-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!