I would like to import a nested jinja macro into a rest file and call it.
So we have main.rst file which imports a collection_of_macros.jinja and inside the collection_of_jinja_macros.jinja is a list of imports which are importing jinja macros.
main.rest file has:
{% import 'path/collection_of_jinja_macros.jinja' as macros%}
{{macros.macro1() }}
then the collection_of_jinja_macros.jinja has
{% include 'path/macro1.jinja' %}
{% include 'path/macro2.jinja' %}
I've tried using include,import, and toctree syntax to pull in the macros but I can never find success.
The rest file cannot never resolve the macro lookup.
Related
How to set up/embed github profile or github repository cards on your Jekyll personal website?
I am expecting to embed my personal projects from github in the form of widgets on my personal website.
I don't see a direct way to include data in static Jekyll HTML files.
But there are options:
GitHub offers a JSON API for repos and users. Not sure what profile information you're looking for.
Jekyll has data files in YAML where you can store this data and read information from.
My initial idea is to get data in JSON and convert it to YAML, manually or programmatically. Then, you can build a Jekyll site that reads the information from the YAML files.
You can try out the manual way:
Read data from https://api.github.com/users/cadamini/repos using https://reqbin.com/
Convert the resulting JSON file using https://www.json2yaml.com/
Put the resulting YAML file in your Jekyll instance, e.g in _data/github/repos.yml (exclude the hyphens).
Extract:
- id: 540417594
node_id: R_kgDOIDYeOg
name: add-theme-github-pages-demo
full_name: cadamini/add-theme-github-pages-demo
private: false
Use the following code/syntax to access the information:
{% for item in data.github.repos %}
{{ item.name }}
{% endfor %}
How do I access static files in a collection?
I have (I think) followed the instructions at
https://jekyllrb.com/docs/collections/
I created a dir ./_test and static files ./_test/a and ./_test/b and added a corresponding collection entry in _config.yml:
collections:
- test
After this I cannot use site.test.files to get an array containing the files ./_test/a and ./_test/b (as should be possible, per my interpretation of the above Jekyll documentation).
(I use the Jekyll version provided by GitHub-Pages.)
Say you have both, some files with yaml front matter and static files witch are not processed by jekyll. These files can be accessed as follows:
files with front matter:
{% assign test_docs = site.test %}
{{ test_docs }}
static files:
{% assign test_coll = site.collections | where: "label", "test" | first %}
{{ test_coll.files }}
As you asked explicitly for static files, in the code above {{ test_coll.files }} contains the array with both files /_test/a and /_test/b. But, only if these files do not have a yaml front matter.
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/
Is there a way within PhpStorm that I can assign a *.tpl file as it's Smarty type but also a Vue file, as it does contain Vue code and it would be nice to have the {{ variable }} recognized.
I'm using couchdb\couchapp to host a web application.
I comes from Django, and with jinja2 I'm able to extend templates in two ways:
{% include "header.html" %}
or
{% extends "base.html" %} <<<---- preferred
I'm looking for a way to do the same with CouchDB, now I have header and footer code written in every single page and, obv, it doesn't look as best practice.
Thank you in advance.
Couch db supports common js modules which means that you can export the mustache/or other templating library as a string and then require it in your show function. More explanation on this mail archive
If you want to use JavaScript on the server side, you'll need to store it as a
property on your design doc. So in a "lib" folder (outside of _attachments)
with the 'couchapp' it will get included like:
couchapp folder
_id file
|_ _attachments folder
|_ ...clientside media...
|_ lib folder
|_ mustache.js
<---->
{_id:"", _attachments: {...}, lib:{mustache:""}}
Then you would use it in a _show/_list/_update function with var Mustache =
require('lib/mustache'). When I do need a library both server and clientside
with 'couchapp', I tend to symlink it so it appears in both _attachments and
other properties.
hope this helps,
-natevw