• DEVHIDE
    • Home (current)
    • About
    • Contact
    • Cookie
    • Home (current)
    • About
    • Contact
    • Cookie
    • Disclaimer
    • Privacy
    • TOS
    Login Or Sign up

    PostsController for href attribute

    124 Views Asked by dharmatech At 28 August 2021 at 19:05 2025-12-20T05:43:25.538994

    The following:

    instance View EditView where
        html EditView { .. } = [hsx|
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href={PostsAction}>Posts</a></li>
                    <li class="breadcrumb-item active">Edit Post</li>
                </ol>
            </nav>
            <h1>Edit Post</h1>
            {renderForm post}
        |]
    

    is from the code for the Blog project in the Creating Your First Project section of the IHP guide.

    I've mostly converted it from HSX to blaze-html here:

    instance View EditView where
        html EditView { .. } = do
            H.nav $ do
                H.ol ! A.class_ "breadcrumb" $ do
                    H.li ! A.class_ "breadcrumb-item" $ do
                        H.a ! A.href "PostsAction" $ do
                            "Posts"
                    H.li ! A.class_ "breadcrumb-item active" $ do
                        "Edit Post"
            H.h1 "Edit Post"
            renderForm post
    

    The last bit I'm wondering about is this one:

    <a href={PostsAction}>Posts</a>
    

    If I do the following:

    H.a ! A.href PostsAction $ do
        "Posts"
    

    I get this message:

    • Couldn't match expected type ‘H.AttributeValue’
                  with actual type ‘PostsController’
    • In the first argument of ‘A.href’, namely ‘PostsAction’
      In the second argument of ‘(!)’, namely ‘A.href PostsAction’
      In the expression: H.a ! A.href PostsActiontypecheck
    PostsAction
    Defined at /home/dharmatech/Dropbox/Documents/ihp-blog/blog/Web/Types.hs:13:7
    

    What's a good way to pass PostsAction to A.href?

    (If there are other ways to make the blaze-html expression more idiomatic, feel free to recommend as well. :-))

    Update 1

    When I use the following, along the lines of what Willem suggested in his answer below:

    instance View EditView where
        html EditView { .. } = do
            H.nav $ do
                H.ol ! A.class_ "breadcrumb" $ do
                    H.li ! A.class_ "breadcrumb-item" $ do
                        H.a ! A.href (fromString (show PostsAction)) $ do
                            "Posts"
                    H.li ! A.class_ "breadcrumb-item active" $ do
                        "Edit Post"
            H.h1 "Edit Post"
            renderForm post
    

    I get the following:

    • Couldn't match type ‘Text’ with ‘[Char]’
      Expected type: String
        Actual type: Text
    • In the first argument of ‘fromString’, namely
        ‘(show PostsAction)’
      In the first argument of ‘A.href’, namely
        ‘(fromString (show PostsAction))’
      In the second argument of ‘(!)’, namely
        ‘A.href (fromString (show PostsAction))’typecheck
    

    Perhaps I need to import a Text version of fromString?

    Update 2

    I've added the following import:

    import Data.String(IsString(fromString))
    

    However, the error message is the same:

    • Couldn't match type ‘Text’ with ‘[Char]’
      Expected type: String
        Actual type: Text
    • In the first argument of ‘fromString’, namely
        ‘(show PostsAction)’
      In the first argument of ‘A.href’, namely
        ‘(fromString (show PostsAction))’
      In the second argument of ‘(!)’, namely
        ‘A.href (fromString (show PostsAction))’typecheck
    

    Update 3

    If I hover over show the following signature is shown:

    show :: forall a. Show a => a -> Text
    

    And for fromString:

    fromString :: forall a. IsString a => String -> a
    

    So I believe that's where the mismatch is.

    Update 4

    This being a typical IHP view file, I have the following at the top for imports:

    module Web.View.Posts.Edit where
    import Web.View.Prelude
    
    import qualified Text.Blaze.Html5 as H
    import qualified Text.Blaze.Html5.Attributes as A
    
    haskell blaze-html ihp
    Original Q&A
    1

    There are 1 best solutions below

    9
    willeM_ Van Onsem willeM_ Van Onsem On 28 August 2021 at 19:20 BEST ANSWER

    As the documentation on Inline Haskell says:

    If the variable is another HSX expression, a blaze HTML element, a text or string: it is just included as you would expect.

    If the variable is any other custom Haskell data structure: it will first be converted to a string representation by calling show on it. You can add a custom ToHtml (import it from IHP.HSX.ToHtml) instance, to customize rendering a data structure.

    So unless there was a ToHTML in the [hsx|…] quasiquoter for {PostAction}, you thus should apply show, next we call fromString :: IsString a => String -> a to it to convert it to an AttributeValue.

    The code is thus equivalent to:

    instance View EditView where
        html EditView { .. } = do
            H.nav $ do
                H.ol ! A.class_ "breadcrumb" $ do
                    H.li ! A.class_ "breadcrumb-item" $ do
                        H.a ! A.href (fromString (show PostsAction)) $ do
                            "Posts"
                    H.li ! A.class_ "breadcrumb-item active" $ do
                        "Edit Post"
            H.h1 "Edit Post"
            renderForm post

    Related Questions in HASKELL

    • Cabal sandbox is using a global dependency. Could not resolve
    • Haskell lens: let binding of Traversal'
    • How can I parse fixed-length, non-delimited integers with attoparsec?
    • Pipeline-like operation using TChan
    • compile-time vs. run-time cost of Hamlet templates
    • Date-time package in haskell - error in the current one, can't find an analog
    • How does one debug infinite recursion in Haskell?
    • Force GHC using local files
    • List with random numbers in Haskell
    • Changes in other elements based on listbox selections in threepenny-gui
    • Multithreading and gtk2hs
    • Operator section for applicative with <$> and <*>
    • Unable to create a custom header to use it in "withManager"
    • How do I reuse an intermediate value in chain of Haskell Either binds?
    • Haskell, Tree problems

    Related Questions in BLAZE-HTML

    • Parsec, read text ended by a string
    • Is there a less awkward way to use blaze-html with a Reader monad?
    • Text.Html vs Blaze.Html
    • How do I use svg-builder Elements in blaze-html?
    • Blaze Templating - Attribute with no value
    • using yesod without Shakespeare
    • Blaze-html type error inside forM_ block
    • Using Blaze on meteor is not working the way tutorials say it will
    • Escaping ampersands in Blaze Html
    • PostsController for href attribute
    • Parse html to Text.Blaze.Html
    • Can't intersperse " " and unwords be used as drop in replacements for each other?
    • Meteor Router - how can I detect if current route requires user to be logged in
    • Blaze-html class attribute chaining / appending / concatenation?
    • making purescript-blaze and purescript-jquery work together

    Related Questions in IHP

    • How do I change the <title> in an IHP app?
    • ihp/nix how to add wreq to dependencies without compile failing?
    • Following IHP guide seeing: Web/Controller: getDirectoryContents:openDirStream: does not exist
    • How can I customize 404 in IHP?
    • Does IHP run migrations atomically?
    • Couldn't match expected type ‘Text’ with actual type ‘Data.MonoTraversable.Element mono0’ The type variable ‘mono0’ is ambiguous
    • Could not deduce (IHP.RouterSupport.AutoRoute (Id' "hardwareVendors"))
    • How to use forEach with multiple traversables?
    • Error when calling function that returns HTML within email template
    • IHP - How to connect IHP's Postgres instance with Moodle?
    • Localizing an IHP application
    • How can I pass List params in IHP forms?
    • Getting imports right in Helper files in IHP
    • IHP - How to send an attachment as a response from IHP Action?
    • Is there a specific pattern for tracking Header Referrer Data in IHP apps?

    Trending Questions

    • UIImageView Frame Doesn't Reflect Constraints
    • Is it possible to use adb commands to click on a view by finding its ID?
    • How to create a new web character symbol recognizable by html/javascript?
    • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
    • Heap Gives Page Fault
    • Connect ffmpeg to Visual Studio 2008
    • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
    • How to avoid default initialization of objects in std::vector?
    • second argument of the command line arguments in a format other than char** argv or char* argv[]
    • How to improve efficiency of algorithm which generates next lexicographic permutation?
    • Navigating to the another actvity app getting crash in android
    • How to read the particular message format in android and store in sqlite database?
    • Resetting inventory status after order is cancelled
    • Efficiently compute powers of X in SSE/AVX
    • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

    Popular # Hahtags

    javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

    Popular Questions

    • How do I undo the most recent local commits in Git?
    • How can I remove a specific item from an array in JavaScript?
    • How do I delete a Git branch locally and remotely?
    • Find all files containing a specific text (string) on Linux?
    • How do I revert a Git repository to a previous commit?
    • How do I create an HTML button that acts like a link?
    • How do I check out a remote Git branch?
    • How do I force "git pull" to overwrite local files?
    • How do I list all files of a directory?
    • How to check whether a string contains a substring in JavaScript?
    • How do I redirect to another webpage?
    • How can I iterate over rows in a Pandas DataFrame?
    • How do I convert a String to an int in Java?
    • Does Python have a string 'contains' substring method?
    • How do I check if a string contains a specific word?
    .

    Copyright © 2021 Jogjafile Inc.

    • Disclaimer
    • Privacy
    • TOS
    • Homegardensmart
    • Math
    • Aftereffectstemplates