在IHP的Helper文件中正确导入导入

问题描述

我试图将我的某些视图和控制器逻辑集中到Application.Helper.ControllerApplication.Helper.View中各自的帮助文件中的帮助程序中。

我发现我无权访问自己有权访问的程序包,例如在控制器文件中。例如Data.Text和其他很多东西。当我什至无法使用管道操作员时,我就停止尝试全部导入它们。

View.hs帮助文件相同,无法访问hsx语法。

有一种简单的方法可以解决此问题吗?您如何解决呢?必须在这里手动进行进口吗?

Web/Controller文件夹中创建Helper文件对我来说似乎更简单,因为该文件夹中的模块似乎可以正确正确地自动导入。

我现在的Controller.hs文件不支持Data.Text和管道运算符之类的东西:

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

不支持hsx语法的View.hs:

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

解决方法

Application.Helper.Controller中,您需要导入IHP.ControllerPrelude,如下所示:

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

Application.Helper.View中,您需要导入IHP.ViewPrelude,如下所示:

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

应该适当地将其添加到IHP项目模板中。