Getting imports right in Helper files in IHP

104 Views Asked by At

I am trying to centralize some of my view and controller logic into helpers in their respective helper files in Application.Helper.Controller and Application.Helper.View.

I am finding that I don't have access to the packages I have access to for example in my controller files. Like for example Data.Text and lots of others. I stopped trying to import them all when I didn't even have access to the pipe operator.

Same with the View.hs helper file does not have access to the hsx syntax.

Is there a simple way to fix this? How do you solve this? Must imports be made manually here?

It would seem simpler to me to make Helper files inside the Web/Controller folder as the modules inside that folder seems to do the correct automatic imports with no issue.

My Controller.hs file as it looks now, not supporting stuff like Data.Text and pipe operator:

module Application.Helper.Controller (
    module IHP.LoginSupport.Helper.Controller
) where

-- Here you can add functions which are available in all your controllers

import IHP.LoginSupport.Helper.Controller
import Generated.Types


type instance CurrentUserRecord = User

and the View.hs, that does not support the hsx syntax:

module Application.Helper.View (
    -- To use the built in login:
    module IHP.LoginSupport.Helper.View
) where

-- Here you can add functions which are available in all your views

-- To use the built in login:
import IHP.LoginSupport.Helper.View

1

There are 1 best solutions below

2
On BEST ANSWER

In Application.Helper.Controller you need to import IHP.ControllerPrelude, like this:

module Application.Helper.Controller (
    module IHP.LoginSupport.Helper.Controller
) where

-- Here you can add functions which are available in all your controllers

import IHP.LoginSupport.Helper.Controller
import Generated.Types
import IHP.ControllerPrelude


type instance CurrentUserRecord = User

In Application.Helper.View you need to import IHP.ViewPrelude, like this:

module Application.Helper.View (
    -- To use the built in login:
    module IHP.LoginSupport.Helper.View
) where

-- Here you can add functions which are available in all your views

-- To use the built in login:
import IHP.LoginSupport.Helper.View
import IHP.ViewPrelude

This should propably be added to the IHP project template.