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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. By default, the filter will wrap all text into a paragraph. To disable that, you can
  25. pass `true` to the inline argument:
  26. ```jinja2
  27. {{ some_text | markdown(inline=true) }}
  28. ```
  29. ### base64_encode
  30. Encode the variable to base64.
  31. ### base64_decode
  32. Decode the variable from base64.
  33. ## Built-in global functions
  34. Gutenberg adds a few global functions to Tera in order to make it easier to develop complex sites.
  35. ### `get_page`
  36. Takes a path to a `.md` file and returns the associated page
  37. ```jinja2
  38. {% set page = get_page(path="blog/page2.md") %}
  39. ```
  40. ### `get_section`
  41. Takes a path to a `_index.md` file and returns the associated section
  42. ```jinja2
  43. {% set section = get_section(path="blog/_index.md") %}
  44. ```
  45. ### ` get_url`
  46. Gets the permalink for the given path.
  47. If the path starts with `./`, it will be understood as an internal
  48. link like the ones used in markdown.
  49. ```jinja2
  50. {% set url = get_url(path="./blog/_index.md") %}
  51. ```
  52. This can also be used to get the permalinks for static assets for example if
  53. we want to link to the file that is located at `static/css/app.css`:
  54. ```jinja2
  55. {{ get_url(path="css/app.css") }}
  56. ```
  57. For assets it is reccommended that you pass `trailing_slash=false` to the `get_url` function. This prevents errors
  58. when dealing with certain hosting providers. An example is:
  59. ```jinja2
  60. {{ get_url(path="css/app.css", trailing_slash=false) }}
  61. ```
  62. In the case of non-internal links, you can also add a cachebust of the format `?t=1290192` at the end of a URL
  63. by passing `cachebust=true` to the `get_url` function.
  64. ### `get_taxonomy_url`
  65. Gets the permalink for the tag or category given.
  66. ```jinja2
  67. {% set url = get_taxonomy_url(kind="category", name=page.category) %}
  68. ```
  69. The `name` will almost come from a variable but in case you want to do it manually,
  70. the value should be the same as the one in the front-matter, not the slugified version.
  71. ### `trans`
  72. Gets the translation of the given `key`, for the `default_language` or the `language given
  73. ```jinja2
  74. {{ trans(key="title") }}
  75. {{ trans(key="title", lang="fr") }}
  76. ```