2017-04-01 2 views
2

にウィジェットを直接含めますそれをハンドラやすべての作業にロードできます。イェソドは、私は足場イェソドアプリを持っているとこのようになりますし、別のモジュールに位置するシンプルなウィジェットを作成したテンプレート

twitterUsername :: String 
twitterUsername = "someusername" 

getHomeR :: Handler Html 
getHomeR = do 
    (formWidget, formEnctype) <- generateFormPost sampleForm 
    let submission = Nothing :: Maybe FileForm 
     handlerName = "getHomeR" :: Text 
    defaultLayout $ do 
     let (commentFormId, commentTextareaId, commentListId) = commentIds 
     aDomId <- newIdent 
     setTitle "Some title" 
     twitterWidget twitterUsername 
     $(widgetFile "homepage") 

だから私がやりたいものを別のテンプレートに直接それを使用することですが、私はしようとすると実行します。

^{twitterWidget twitterUsername} 

は私が

• Ambiguous type variable ‘m1’ arising from a use of ‘toWidget’ 
     prevents the constraint ‘(ToWidget App (m1()))’ from being solved. 
     Probable fix: use a type annotation to specify what ‘m1’ should be. 
     These potential instances exist: 
     instance (site' ~ site, IO ~ m, a ~()) => 
       ToWidget site' (WidgetT site m a) 
      -- Defined in ‘Yesod.Core.Widget’ 
     ...plus one instance involving out-of-scope types 
     (use -fprint-potential-instances to see them all) 
    • In the second argument of ‘(GHC.Base..)’, namely ‘toWidget’ 
     In the expression: asWidgetT GHC.Base.. toWidget 
     In a stmt of a 'do' block: 
     (asWidgetT GHC.Base.. toWidget) (twitterWidget twitterUsername) 

を取得するだから私の質問が何であるかであります異なる目的を果たしているウェブサイト上のテンプレートに複数のウィジェットを読み込ませることができますか?

+0

テンプレートのコンテンツを提供できますか? –

+0

このページのテンプレートは、ヘッダーウィジェットとホームページで区切られています。ヘッダーウィジェットはFoundation.hsの各ページにロードされ、ホームページテンプレートにはhtmlだけが含まれているので便利ではないと思います。 – vodich

答えて

1

変更あなたのものに

module Widget.Header where 

import Prelude 
import Yesod 

twitterWidget :: MonadWidget m => String -> m() 
twitterWidget twitteruser = do 
    toWidgetBody([hamlet| <a href="https://twitter.com/#{twitteruser}" .twitter-follow-button data-show-count="false">Follow @#{twitteruser} 
         <script async src="//platform.twitter.com/widgets.js" charset="utf-8"> 
        |]) 

より多くの方法mは間違いIOなり、Haskellはそれを把握する必要はありません

module Widget.Header where 

import Import 

twitterWidget :: Yesod site => String -> WidgetT site IO() 
twitterWidget twitteruser = do 
    toWidgetBody([hamlet| <a href="https://twitter.com/#{twitteruser}" .twitter-follow-button data-show-count="false">Follow @#{twitteruser} 
         <script async src="//platform.twitter.com/widgets.js" charset="utf-8"> 
        |]) 

のような。

+0

それはあなたの助けに感謝しました! – vodich

関連する問題