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 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. For assets it is reccommended that you pass `trailing_slash=false` to the `get_url` function. This prevents errors
  53. when dealing with certain hosting providers. An example is:
  54. ```jinja2
  55. {{ get_url(path="css/app.css", trailing_slash=false) }}
  56. ```
  57. In the case of non-internal links, you can also add a cachebust of the format `?t=1290192` at the end of a URL
  58. by passing `cachebust=true` to the `get_url` function.
  59. ### ` get_taxonomy_url`
  60. Gets the permalink for the tag or category given.
  61. ```jinja2
  62. {% set url = get_taxonomy_url(kind="category", name=page.category) %}
  63. ```
  64. The `name` will almost come from a variable but in case you want to do it manually,
  65. the value should be the same as the one in the front-matter, not the slugified version.