Hey there!
I find your project very interesting and love the idea of it. Unfortunately when I try to use it, I run into a few issues.
- I get a random
TemplateNotFound Exception
. This happens with every template I have, but only when I try to load it for the second (or more) time. So whatever site I visit works without a problem, yet when I try to load a page I have visited before, it shows the error. This happens with all templates; not just the ones using components.
- The components are rendered as text instead of actual html components. Not sure what causes this. Looks similar like using
.innerText
instead of .innerHTML
.
I do not know what causes these issues and I hope you can help me here. Anyways, I hope you continue this amazing project.
EDIT:
After some experimenting: Turns out, the TemplateNotFound Exception
somehow has to do with the {{ catalog.render_assets() }}
-statement. This was included in every page since it was part of the layout, even when there was no components to render. Now that I removed it, the error only shows up when I try to render a page with components and then any page.
Steps to Error:
- open any pages without components; no matter how often -> works fine
- open a page using components -> still works fine except for
2.
- open any page (either reload or switch to any other page) ->
TemplateNotFound Exception
shows
About the error:
- I am using flask
- There are no exceptions before or after the
TemplateNotFound Exception
in the console.
- When using
{{ catalog.render_assets() }}
in the Layout, the assets get linked and loaded correctly.
- The error also occurs when
{{ catalog.render_assets() }}
is removed completely from everywhere.
- When using
{{ catalog.render_assets() }}
everywhere, I can load every page exactly once; when not using {{ catalog.render_assets() }}
or only using it on the page with the component, it behaves as described in Steps to Error
Edit 2:
updated title to ... - partially solved
Turns out this weired behaviour with the TemplateNotFound Exception
only happens when: The folder with the components is not the same folder as the normal template folder.
More information on this:
I tried to recreate this exception on a blank flask project and failed at first. Only when I recreated the file structure of my original project I succeeded. My file structure looks something like this:
- templates:
-- index.html
-- others.html
-- ... .html
-- components:
--- Layout.jinja
--- Component.jinja
--- Other.jinja
When including the directories with catalog.add_folder
I only added the folders actually containing components and styles/scripts for the components (templates/components
, static/components/styles
, ...). I did not however include the normal templates (templates
). Even though none of the normal templates used components, after first using a component on any template, all templates not registered with jinjax became globally unavailable.
Steps to recreate:
- Create a blank flask project with the default project structure
- Create some jinja2 templates (without using jinjax)
- Add a folder for components and fill it with at least one jinjax component
- register the jinjax component folder with the catalog, but not the templates folder
- create a template using the component
- start the app
- navigate between the pages not using jinjax components without problems
- open a page using jinjax components - still works
- try to open any other page in the templates folder - flask breaks
Edit 3:
Changed title to TemplateNotFound Exception and weired Text Error - BUG
I figured out the issue with The components are rendered as text...
as well:
Turns out this happens when there is no content inside a Component. Either when using the self-closing Syntax (<Component/>
) or when just leaving the content blank (<Component></Component>
). This for some reason renders the component as text. It does not matter whether the content is actually used inside the component (with {{ content }}
). Leaving a space between the open- and closing tags (content = " "
) solves this issue.