haml 语法 - 更好的编写方式?

发布于 2024-08-10 23:34:02 字数 856 浏览 6 评论 0原文

一定有更好的写法 - 我只是不确定如何(使用 staticmatic)-

- if current_page.include? "0.html"
  - @current_index = 1
- if current_page.include? "1.html"
  - @current_index = 2
- if current_page.include? "2.html"
  - @current_index = 3
- if current_page.include? "3.html"
  - @current_index = 4
- if current_page.include? "4.html"
  - @current_index = 5
- if current_page.include? "5.html"
  - @current_index = 6
- if current_page.include? "6.html"
  - @current_index = 7
- if current_page.include? "7.html"
  - @current_index = 8
- if current_page.include? "8.html"
  - @current_index = 9
- if current_page.include? "9.html"
  - @current_index = 10
- if current_page.include? "10.html"
  - @current_index = 11
- if current_page.include? "11.html"
  - @current_index = 12

There must be a better way of writing this- I'm just not sure how (using staticmatic)-

- if current_page.include? "0.html"
  - @current_index = 1
- if current_page.include? "1.html"
  - @current_index = 2
- if current_page.include? "2.html"
  - @current_index = 3
- if current_page.include? "3.html"
  - @current_index = 4
- if current_page.include? "4.html"
  - @current_index = 5
- if current_page.include? "5.html"
  - @current_index = 6
- if current_page.include? "6.html"
  - @current_index = 7
- if current_page.include? "7.html"
  - @current_index = 8
- if current_page.include? "8.html"
  - @current_index = 9
- if current_page.include? "9.html"
  - @current_index = 10
- if current_page.include? "10.html"
  - @current_index = 11
- if current_page.include? "11.html"
  - @current_index = 12

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七月上 2024-08-17 23:34:02
- 0.upto(11) do |n|
  - if current_page.include? "#{n}.html"
    - @current_index = n + 1
- 0.upto(11) do |n|
  - if current_page.include? "#{n}.html"
    - @current_index = n + 1
橙幽之幻 2024-08-17 23:34:02
- @current_index = current_page[/(\d+)\.html/, 1].to_i + 1
- @current_index = current_page[/(\d+)\.html/, 1].to_i + 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文