My project is separated into many modules.
Each module has its own /templates folder that contains its own relevant template files.
There are common components (header, nav) inside these template files that I wish to extract into 'partials' which are then included inside the each module's template files (ie: {% include 'nav.html' %}
The Question
How can I set up my template environment in such a way that allows for the module's template files to reach into a shared folder that contains these partials?
My Current Environment Setup
template_dir = os.path.join(os.path.dirname(__file__), 'views')
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir),
autoescape=True)
self.render('some_template.html', env=env) # render function
This current configuration only allows me to reach into the /templates folder within each module. However, the templates files (inside the /templates dir) should also have access to the partial files that are outside of each module's directory.
Ideally, the app directory would look like this:
app/
shared/
header.html <-- templates within modules need to access these
nav.html
modules/
module_a/
handler.py
templates/
my_template.html <-- needs access to partials from 'shared/'
module_b/
module_c/
Related
With Express, I am trying to acess relative path (css/..., assets/...) inside HTML file.
I can't use express.static() because the HTML file is located in a dynamically generated folder, with a hash as its name.
There are many folders with a different set of files inside, these folders are in "public/assets/template/file/tmp".
The server is trying to access these files based on what was defined in express.static, which was "path.join(__dirname,'public')", in order to handle other files in the project.
The public folder (which is in the project root) looks like this:
The index.html head:
I couldn't think of anything to do in this current situation, perhaps set a different express.static when accessing files in the dynamically generated folder, but it doesn't look like the best approach (not even sure if it's possible).
I want to know how can we lazy load JSON files in angular application. As per my understanding, static content in assets folder is loaded by default at the time of initial rendering only and is present in browser memory. I want only specific JSON files to be loaded in browser on demand. Can someone please explain how to do that.
It is not mandatory to place all your static content inside assets folder of the app module. you can create assets folder at module level. so that those content will be loaded when the module is loaded.
app/
modules/
module_1/
assets/
images/
image_module_1.png
module_1.component.ts
module_1.module.ts
module_2/
assets/
images/
image_module_2.png
module_2.component.ts
module_2.module.ts
app.module.ts
In case of above hierarchy if module_2 is lazy loaded then the assets will also be downloaded when module is loaded.
I've inherited a process that converts markdown content into html using jekyll.
If I remove the yaml front matter between ---, by client request to simplify the process for editors,
---
product: Product Name
capability: testing
infotype: Overview
audience:
---
# Testing file 2
This is another testing file.
The jekyll build doesn't convert the file.
# Testing file 2
This is another testing file.
When I have the front matter in the testing 2 file I see the following in the log when running build --verbose
Rendering: user-administration/testing-file-2.md
Pre-Render Hooks: user-administration/testing-file-2.md
Rendering Markup: user-administration/testing-file-2.md
Rendering Layout: user-administration/testing-file-2.md
but without the front matter there is no message in the log related to testing-file-2.md
This testing-file-2.md is part of a collection of other files that have metadata. They are render into an html website but not the testing-file-2.md when the metadata is removed.
Is there a way for jekyll to build and render files without front matter?
Jekyll does not ignore any files. Rather, for each file, it decides whether the file is:
a static file, which can be copied as-is to the output folder (_site), or
a file to be processed first.
Markdown files (.md) are processed by kramdown and Liquid if they start with YAML frontmatter:
---
---
otherwise they are treated as static files, and copied to _site with no processing.
There is a workaround that might work for you using include_relative; but it may cause more trouble for your client's editors than it's worth, depending how they work.
You can include a static file inside a file to be processed. Your static file might be plain-text.md:
# Static text file
This is a file with no YAML frontmatter.
Then, separately, you create a markdown file with frontmatter that will include the plain-text file inside it. Say, processed-text.md:
---
---
{% include_relative plaintext.md %}
Then your plain text will be processed and appear on your site as /processed-text. Think of the file processed-text.md as a kind of template for holding plain-text.md.
You'll want to see the docs on include_relative, especially the fact that the file to be included can't be above the including file in the file system.
I've read that it's a requirement to have at minimum at empty front matter or jekyll will ignore the file
---
---
I'm pretty sure I've seen in Jekyll blog projects with multiple source document directories, such as _posts and _pages, but the source parameter in the _config.yml file can only take 1 directory as its argument, and neither an array nor a space separated string of directories works.
Am I misunderstanding the meaning of the source parameter? I'm expecting it to be used by watch to specify which files' changes will trigger a build, and which files to build.
Also, I have fragments such as about.md which can be included in other pages. What is the best location for files like this one?
The source configuration refers to your <project_root>, not individual directories within the project root. By default, its set to your current_directory (the location from where you are running jekyll build (or) serve.
Jekyll watches all nested files and directories deep within the source directory by default.
about.md is not meant to be seen as a fragment to be included in other files. Its a full-blown "page" that would render into _site/about.html or _site/about/index.html depending on your permalink settings.
Fragments to be included in other pages live inside the _includes directory and are inserted via the Liquid construct {% include <fragment-filename>.html %}
Other than _layouts, _includes and _sass, directories that start with an underscore are ignored by Jekyll unless you configure Jekyll to see them as "collections". _posts is a pre-defined and hard-coded collection directory.
For more information on Jekyll, refer the official documentation at https://jekyllrb.com
If anyone, like me, is looking to include several source folders in github-pages, you can simply configure the jekyll root in github-page on the master branch. I.e. not on gh-page branch, nor on the docs folder.
Thus, all folder is processed. README.md are treated as index.md and you can easily make relative links from the main README.md at the root to any other doc which are "below" it in the file hierarchy. Thus having jekyll cover all your code documentation.
This is my first time working with Django and while I'm finding the tutorial they provide to be very helpful, there is one major issue I'm having moving forward with my project.
The most confusing aspect of Django so far is the layout of files in a project. As of now, the layout of my project is as follows:
webapp/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
app/
__init__.py
models.py
tests.py
views.py
Bear with my naming here, I created a Django project "mysite" and an app "app". Here are the questions I find myself continually returning to:
I've noticed that in mysite/settings.py there is a section for apps, would I include the app I'm writing in this project in that section once I've finished it?
If I were to want to create a simple index.html page, where would a file like that go in this project organization?
I've read that static content like CSS or image files need to be contained within a simple "static" directory. Where would this go in this project organization? [ This would be for debugging purposes only, I've read this should never be done for production ]
My main goal right now is to just be able to view a simple html site before I begin delving into the models and views of the app I'm creating.
If your app needs one or more setting variables, then yes, you would put those in mysite/settings.py
Create a new folder mysite/templates/. This is where you want to put your template files. Organize your templates per app: mysite/templates/app/ would have the templates used by your app views. If you want to serve static templates such as a simple static index.html, then just throw that file in mysite/templates/index.html and then add the following to your urls.py file (no need to create a view for the index):
(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}),
Static content would end up in something like mysite/static after you run the collectstatic command. See managing static files. The collectstatic command searches for static files in all locations specified in STATICFILES_DIRS and deploys them into the folder specified in STATIC_ROOT (mysite/static).