Matrix partials allow you to bring external code in to your SiteWrench Matrix templates. This is most useful because it allows you to keep your Matrix code under version control with GIT. This also allows you to reuse code across multiple matrices on a site.
Note: To see changes in your partial files, you will have to make a change in Matrix in SiteWrench and Save to clear the cache.
Template partials directory
In the Matrix Details panel, set the partials directory where you are keeping your code in Git. The path to the directory is always going to be: ~sitefiles/[siteId]/[yourDirectoryName]
For this example, the directory name is /partdir and it lives in Buddy here:
Partial File Names (Important!)
There are two key requirements for your file names.
- Your file name must end with .liquid
- Your file name must begin with an underscore (ex: _filename.liquid)
In this example, the partial file is named _partialfile.liquid
Including Partial Files
To include your partial file in a Matrix, use the following syntax:
{% include 'yourFileName' %}
NOTE: your reference to your partial file does NOT include the .liquid extension and does NOT include the underscore.
Variables and Partials
Partials can access variables created in the Matrix templates. Meaning that if in you create a variable in the SiteWrench template, you can reference that variable in the partial.
SiteWrench Matrix templates can access variables created in a Partial. Meaning that if you create a variable in a partial, you can use it in a Matrix template.
CAVEAT: The variable must be created "above" where it is used (just like JavaScript).
This works:
{{ assign myVar = "some value" }}
{% include 'myPartialFileName' %}
--
You can access myVar in _myPartialFileName.liquid
--
This will not work:
{% include 'myPartialFileName' %}
{{ assign myVar = "some value" }}
--
Because templates are processed sequentially, _myPartialFileName.liquid
will not be able to access the variable.
--
Comments
1 comment
<3 Matrix
Please sign in to leave a comment.