Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewing templates before creating them doesn't work #63

Open
simonwo opened this issue Sep 17, 2024 · 2 comments · May be fixed by #119
Open

Viewing templates before creating them doesn't work #63

simonwo opened this issue Sep 17, 2024 · 2 comments · May be fixed by #119
Assignees
Labels
bug Something isn't working

Comments

@simonwo
Copy link
Member

simonwo commented Sep 17, 2024

The Prototype Kit includes a "Templates" page when run in development mode that allows the designer to create pages from templates exposed by plugins, or to view them before creating them.

In testing we observed designers using the View feature, but in our plugin viewing templates doesn't work. This is because macros defined in plugin code don't get exported to template viewing but they do in pages.

We can redefine some of our exported functions as pure macros, but not all of them due to limitations with Nunjucks. So we need to come up with some way to get functions loaded during template viewing (including possibly submitting a patch to the Prototype Kit).

@simonwo simonwo added the bug Something isn't working label Sep 17, 2024
@rossjones rossjones self-assigned this Sep 18, 2024
@rossjones
Copy link
Collaborator

rossjones commented Sep 19, 2024

Currently we define these functions in the plugin for use in the prototype by passing in a reference to the prototype kit in our initialisation call. Unfortunately, the prototype kit seems designed for people to add functions within the prototype itself and not from plugins. Mentions of plugin config key nunjucksFunctions seem to load functions from the app's functions.js file, rather than the plugins.

The plugin does not currently have a dependency on the prototype kit, because we don't want the circular reference, making it impossible to add a function at the global level in the plugin unless the manage-plugin pages call our initialise function.

We might be able to extend the prototype kit to optionally locate/call a specific function to initialise the plugin, in much the same way that other plugin systems dlsym a function to return a structure of pointers to functions. We could discover a specific function signature and call it with config and reference to the library etc. Whether we can get this merged in a reasonable time-frame is another question.

@rossjones
Copy link
Collaborator

Had a look at trying to wrap the main content in the templates with a check for the existence of a specific function, and it's fine, it hides the existing content. Unfortunately, if we have an else block to show some static content when previewing the page then:

  • It can't use any of the existing macros that use functions, (e.g. it's not just the path functions)
  • Any macros we used to provide static content would appear in the template when the template was installed (and would be broken)

It's also probably true that there'll be a problem if you install a template before you've added the initialisation code as the functions won't be available.

@rossjones rossjones linked a pull request Nov 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants