Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Variables

Dmitry Shevtsov edited this page Apr 15, 2021 · 3 revisions

We use Jekyll variables at the Magento Docs projects based on Jekyll.

There are three scopes of variables available:

  • global
  • page
  • local

Each variable is available using Liquid syntax for variables {{ }} and an object to get the variable from. For example, for the baseurl value of the site object, it is {{ site.baseurl }}.

Global

There are two objects available globally that we use for variables:

  • site
  • data

Site

Through the site object, you can get any key from the site's configuration, defined in _config.yml.

The most commonly used are:

  • {{ site.baseurl }} which returns value of the baseurl key of the _config.yml file. Typically, it is used for links to HTML pages of versionless topics. Example: {{ site.baseurl }}/cloud/bk-cloud.html. For more technical details, see Clearing Up Confusion Around baseurl -- Again.
  • {{ site.downloads }} which returns value of the downloads key of the _config.yml file. It points to the folder with downloadable files, which is not part of this repository. Example: {{ site.downloads }}/magento-commerce-cloud-prelaunch-checklist.pdf
  • {{ site.mage2bloburl }} which returns value of the mage2bloburl key of the _config.yml file. It contains starting part of a URL to blob of the magento2 repository. Use it when you want to add a link to code file from the magento2 repository. Examples:
    • in a versionless topic, to point to the latest released version of the code: {{ site.mage2bloburl }}/{{ site.version }}/auth.json.sample
    • in a versionless topic, to point to a specific version of the code: {{ site.mage2bloburl }}/2.3/auth.json.sample
    • in a versioned topic: {{ site.mage2bloburl }}/{{ page.guide_version }}/auth.json.sample
  • {{ site.gdeurl }} which returns value of the gdeurl key of the _config.yml file. It is used to reference versioned topics of the lates version from versionless pages.
  • {{ site.version }} which returns value of the version key of the _config.yml file. It contains the latest released minor version.

NOTE Versioned topics are topics, located at the guides directory and put under a particular version. All other topics are considered versionless.

Data

The data list is available via {{ site.data }}. It allows accessing the data stored in the src/_data directory. We use this data to generate tables or big chunks of content, as well as any other global data that does not relate to the site's configuration.

For example, the {{ site.data.var.ee }} value returns the ee key of the src/_data/var.yml file

See Data Files.

Page

Every topic is a page object. Page parameters can be assigned in different ways:

  • Default parameters are natively defined by Jekyll. Examples: {{ page.path }}, {{ page.content }}, {{ page.url }}. Default parameters can be overridden by plugins.
  • Custom parameters can be added to multiple pages using plugins. Examples: {{ page.github_path }}, {{ page.last_modified_at }}, {{ page.baseurl }}
  • Custom parameters can be added to multiple pages using defaults in the _config.yml. Examples: {{ page.guide_version }}, {{ page.github_repo }}
  • Custom parameters can be added to a single page using front matter. Examples: {{ page.title }}, {{ page.group }}. A value from front matter has the highest priority over above types of assignments.

Local

A topic can have simple Liquid variables. For example, to avoid typing {{ site.data.var.ee }} when you have to use it multiple time in your topic, you can use a Liquid variable for this:

{% assign ce = site.data.var.ee %}

and refer to it as {{ce}}.