哈姆雷特模板中的 $forall 出现问题

发布于 2024-12-04 17:00:14 字数 1494 浏览 0 评论 0原文

我对哈姆雷特有一个奇怪的问题。我试图使用 $forall 来迭代列表,但我不断收到“不在范围内”错误。我在Win7上运行yesod 0.9.2.2。

除了糟糕的设计之外,有人知道我哪里出了问题吗?删除“db”的变量插值可以让执行正常。

相关的村庄:

 !!!
<h1> Database List
<hr>
<table>

  <tr>
       <td> Host
       <td> Status
  $forall db <- dbList
  <tr>
       <td> #{host db}

相关的处理程序代码:

data Database = Database {dbType :: DBType,
                        host :: String,
                        user :: String,
                        password :: String
                       }


dbList = [Database Oracle "cpalmerws" "system" "***",
          Database Oracle "bdblnx" "system" "***",
          Database Postgres "localhost" "postgres" "***"]

getDBStatusR :: Handler RepHtml
getDBStatusR = do
  mu <- maybeAuth
  defaultLayout $ do
    setTitle "DB Status Page"
    addWidget $(widgetFile "dbstatus")

我在运行 yesod devel 时收到此错误:

Handler\DBStatus.hs:47:17:
    Not in scope: `db'
    In the result of the splice:
      $(widgetFile "dbstatus")
    To see what the splice expanded to, use -ddump-splices
    In the first argument of `addWidget', namely
      `$(widgetFile "dbstatus")'
    In the expression: addWidget ($(widgetFile "dbstatus"))
Starting development server...

dist\devel.hs:3:1:
    Failed to load interface for `Application':
      it is not a module in the current program, or in any known package.
Exit code: ExitFailure 1

I'm having a strange issue with hamlet. I'm trying to use $forall to iterate through a list, but I keep getting a "Not in scope" error. I'm running yesod 0.9.2.2 on Win7.

Terrible design aside, anyone have any idea where I'm going wrong? Removing the variable interpolation of "db" lets in execute fine.

The relevant hamlet:

 !!!
<h1> Database List
<hr>
<table>

  <tr>
       <td> Host
       <td> Status
  $forall db <- dbList
  <tr>
       <td> #{host db}

The relevant handler code:

data Database = Database {dbType :: DBType,
                        host :: String,
                        user :: String,
                        password :: String
                       }


dbList = [Database Oracle "cpalmerws" "system" "***",
          Database Oracle "bdblnx" "system" "***",
          Database Postgres "localhost" "postgres" "***"]

getDBStatusR :: Handler RepHtml
getDBStatusR = do
  mu <- maybeAuth
  defaultLayout $ do
    setTitle "DB Status Page"
    addWidget $(widgetFile "dbstatus")

I'm getting this error when running yesod devel:

Handler\DBStatus.hs:47:17:
    Not in scope: `db'
    In the result of the splice:
      $(widgetFile "dbstatus")
    To see what the splice expanded to, use -ddump-splices
    In the first argument of `addWidget', namely
      `$(widgetFile "dbstatus")'
    In the expression: addWidget ($(widgetFile "dbstatus"))
Starting development server...

dist\devel.hs:3:1:
    Failed to load interface for `Application':
      it is not a module in the current program, or in any known package.
Exit code: ExitFailure 1

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

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

发布评论

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

评论(1

南七夏 2024-12-11 17:00:14

您在模板中的缩进级别是错误的:

$forall db <- dbList
    <tr>
        <td>#{host db}

在您的版本中,该行超出了 $forall 的范围。

Your indentation level in the template is wrong:

$forall db <- dbList
    <tr>
        <td>#{host db}

In your version the row is outside of $forall's scope.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文