Community
Possibility to reuse server side helper functions in PUG before switching to Helix?
5 days ago by Dennis
Until we switch to Helix it would be helpful to be able to put the server-side helper functions for all PUG forms in a separate file to avoid redundancy and versioning problems.
I try putting a function in a helper file (in a mixin):
//_helper.pug
// A mixin to inject server side helper functions in a block
mixin helpers()
-
function greet({ name }) {
const result = typeof name === "string" ? `Hello, ${name}!` : "Hello, stranger!"
return result
}
and to import it, but without success:
//test.pug
extends ../views/form/default-form
block formContent
//include ../forms/_helpers.pug
//GIVES no such file or directory, open 'templates/forms/_helpers.pug'
//include ../../forms/_helpers.pug
//GIVES no such file or directory, open 'forms/_helpers.pug'
//include ../../../forms/_helpers.pug
//GIVES no such file or directory, open '../forms/_helpers.pug'
//Assume the name of my root folder in the full Onify folder structure is 'app'
include ../../app/forms/_helpers.pug
//GIVES no such file or directory, open 'app/forms/_helpers.pug'
+helpers()
-
const message = greet({ name: 'Test' })
p= message
Possibly because i do not know the name in Onify for my root, or it could be that this is impossible anyway without the PUG basedir option set, which i can not access.
Is there a quickfix here which I'm missing?