You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

overview.md 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. +++
  2. title = "Overview"
  3. weight = 10
  4. +++
  5. Gutenberg uses the [Tera](https://tera.netlify.com) template engine and is very similar
  6. to Jinja2, Liquid or Twig.
  7. As this documentation will only talk about how templates work in Gutenberg, please read
  8. the [Tera template documentation](https://tera.netlify.com/docs/templates/) if you want
  9. to learn more about it first.
  10. All templates live in the `templates` directory and built-in or themes templates can
  11. be overriden by creating a template with same name in the correct path. For example,
  12. you can override the RSS template by creating a `templates/rss.xml` file.
  13. If you are not sure what variables are available in a template, you can just stick `{{ __tera_context }}` in it
  14. to print the whole context.
  15. A few variables are available on all templates minus RSS and sitemap:
  16. - `config`: the [configuration](./documentation/getting-started/configuration.md) without any modifications
  17. - `current_path`: the path (full URL without the `base_url`) of the current page, never starting with a `/`
  18. - `current_url`: the full URL for that page
  19. ## Built-in filters
  20. Gutenberg adds a few filters, in addition of the ones already present in Tera.
  21. ### markdown
  22. Converts the given variable to HTML using Markdown. This doesn't apply any of the
  23. features that Gutenberg adds to Markdown: internal links, shortcodes etc won't work.
  24. ### base64_encode
  25. Encode the variable to base64.
  26. ### base64_decode
  27. Decode the variable from base64.
  28. ## Built-in global functions
  29. Gutenberg adds a few global functions to Tera in order to make it easier to develop complex sites.
  30. ### `get_page`
  31. Takes a path to a `.md` file and returns the associated page
  32. ```jinja2
  33. {% set page = get_page(path="blog/page2.md") %}
  34. ```
  35. ### `get_section`
  36. Takes a path to a `_index.md` file and returns the associated section
  37. ```jinja2
  38. {% set section = get_page(path="blog/_index.md") %}
  39. ```
  40. ### ` get_url`
  41. Gets the permalink for the given path.
  42. If the path starts with `./`, it will be understood as an internal
  43. link like the ones used in markdown.
  44. ```jinja2
  45. {% set url = get_url(path="./blog/_index.md") %}
  46. ```
  47. This can also be used to get the permalinks for static assets for example if
  48. we want to link to the file that is located at `static/css/app.css`:
  49. ```jinja2
  50. {{ get_url(path="css/app.css") }}
  51. ```
  52. In the case of non-internal links, you can also add a cachebust of the format `?t=1290192` at the end of a URL
  53. by passing `cachebust=true` to the `get_url` function.