Skip to content

Commit

Permalink
Generated gh-pages for commit 1b064ed
Browse files Browse the repository at this point in the history
Author: Bohdan Zhuravel <[email protected]>

    [PR-22826] Liquid filters for arrays and hashes (#339)
  • Loading branch information
zhuravel committed Oct 22, 2024
1 parent 5a3e8b5 commit d52062b
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 1 deletion.
93 changes: 93 additions & 0 deletions _sources/campaigns/editor/filters.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,99 @@ Returns ``some string``

|hr|

new\_array
..........

Creates a new array. If arguments are provided, they become the elements of the array.

Liquid

.. code-block:: liquid
{% assign my_array = "" | new_array: "element1", "element2" %}
{% assign empty_array = "" | new_array %}
Array: {{ my_array | json }}
Empty array: {{ empty_array | json }}
Rendered Liquid

.. code-block:: text
Array: ["element1","element2"]
Empty array: []
|hr|

append\_to\_array
.................

Appends elements to an existing array.

Liquid

.. code-block:: liquid
{% assign my_array = "" | new_array %}
{% assign my_array = my_array | append_to_array: "element1", "element2" %}
Array: {{ my_array | json }}
Rendered Liquid

.. code-block:: text
Array: ["element1","element2"]
|hr|

new\_hash
.........

Creates a new hash. If a hash is provided as an argument, it returns that hash.

Liquid

.. code-block:: liquid
{% assign my_hash = "" | new_hash: key: "value", key2: 42 %}
{% assign empty_hash = "" | new_hash %}
Hash: {{ my_hash | json }}
Empty hash: {{ empty_hash | json }}
Rendered Liquid

.. code-block:: text
Hash: {"key":"value","key2":42}
Empty hash: {}
|hr|

assign\_key
...........

Assigns a key-value pair to an existing hash. If the key already exists, its value is updated.

Liquid

.. code-block:: liquid
{% assign my_hash = "" | new_hash: key: "value", key2: 42 %}
{% assign my_hash = my_hash | assign_key: "key2", "value2" %}
{% assign my_hash = my_hash | assign_key: "key3", "value3" %}
Hash: {{ my_hash | json }}
Rendered Liquid

.. code-block:: text
Hash: {"key":"value","key2":"value2","key3":"value3"}
|hr|

values
......

Expand Down
4 changes: 4 additions & 0 deletions campaigns/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#barcode-image">barcode_image</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#base64-encode">base64_encode</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#base64-decode">base64_decode</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#new-array">new_array</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#append-to-array">append_to_array</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#new-hash">new_hash</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#assign-key">assign_key</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#values">values</a></li>
<li class="toctree-l2"><a class="reference internal" href="editor/filters.html#async-rendering">async_rendering</a><ul>
<li class="toctree-l3"><a class="reference internal" href="editor/filters.html#example-1">Example 1</a></li>
Expand Down
69 changes: 69 additions & 0 deletions campaigns/editor/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,75 @@ <h2>base64_decode<a class="headerlink" href="#base64-decode" title="Link to this
<p>Returns <code class="docutils literal notranslate"><span class="pre">some</span> <span class="pre">string</span></code></p>
<p><hr></p>
</section>
<section id="new-array">
<h2>new_array<a class="headerlink" href="#new-array" title="Link to this heading"></a></h2>
<p>Creates a new array. If arguments are provided, they become the elements of the array.</p>
<p>Liquid</p>
<div class="highlight-liquid notranslate"><div class="highlight"><pre><span></span><span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span><span class="na">new_array</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;element1&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;element2&quot;</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">empty_array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span>new_array<span class="w"> </span><span class="p">%}</span>

Array: <span class="p">{{</span><span class="w"> </span><span class="nv">my_array</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
Empty array: <span class="p">{{</span><span class="w"> </span><span class="nv">empty_array</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
</pre></div>
</div>
<p>Rendered Liquid</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Array: [&quot;element1&quot;,&quot;element2&quot;]
Empty array: []
</pre></div>
</div>
<p><hr></p>
</section>
<section id="append-to-array">
<h2>append_to_array<a class="headerlink" href="#append-to-array" title="Link to this heading"></a></h2>
<p>Appends elements to an existing array.</p>
<p>Liquid</p>
<div class="highlight-liquid notranslate"><div class="highlight"><pre><span></span><span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span>new_array<span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>my_array<span class="w"> </span>|<span class="w"> </span><span class="na">append_to_array</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;element1&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;element2&quot;</span><span class="w"> </span><span class="p">%}</span>

Array: <span class="p">{{</span><span class="w"> </span><span class="nv">my_array</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
</pre></div>
</div>
<p>Rendered Liquid</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Array: [&quot;element1&quot;,&quot;element2&quot;]
</pre></div>
</div>
<p><hr></p>
</section>
<section id="new-hash">
<h2>new_hash<a class="headerlink" href="#new-hash" title="Link to this heading"></a></h2>
<p>Creates a new hash. If a hash is provided as an argument, it returns that hash.</p>
<p>Liquid</p>
<div class="highlight-liquid notranslate"><div class="highlight"><pre><span></span><span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_hash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span><span class="na">new_hash</span><span class="o">:</span><span class="w"> </span><span class="na">key</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;value&quot;</span><span class="p">,</span><span class="w"> </span><span class="na">key2</span><span class="o">:</span><span class="w"> </span><span class="mi">42</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">empty_hash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span>new_hash<span class="w"> </span><span class="p">%}</span>

Hash: <span class="p">{{</span><span class="w"> </span><span class="nv">my_hash</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
Empty hash: <span class="p">{{</span><span class="w"> </span><span class="nv">empty_hash</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
</pre></div>
</div>
<p>Rendered Liquid</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Hash: {&quot;key&quot;:&quot;value&quot;,&quot;key2&quot;:42}
Empty hash: {}
</pre></div>
</div>
<p><hr></p>
</section>
<section id="assign-key">
<h2>assign_key<a class="headerlink" href="#assign-key" title="Link to this heading"></a></h2>
<p>Assigns a key-value pair to an existing hash. If the key already exists, its value is updated.</p>
<p>Liquid</p>
<div class="highlight-liquid notranslate"><div class="highlight"><pre><span></span><span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_hash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;&quot;</span><span class="w"> </span>|<span class="w"> </span><span class="na">new_hash</span><span class="o">:</span><span class="w"> </span><span class="na">key</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;value&quot;</span><span class="p">,</span><span class="w"> </span><span class="na">key2</span><span class="o">:</span><span class="w"> </span><span class="mi">42</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_hash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>my_hash<span class="w"> </span>|<span class="w"> </span><span class="na">assign_key</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;key2&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;value2&quot;</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">assign</span><span class="w"> </span><span class="na">my_hash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>my_hash<span class="w"> </span>|<span class="w"> </span><span class="na">assign_key</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;key3&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;value3&quot;</span><span class="w"> </span><span class="p">%}</span>

Hash: <span class="p">{{</span><span class="w"> </span><span class="nv">my_hash</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">json</span><span class="w"> </span><span class="p">}}</span>
</pre></div>
</div>
<p>Rendered Liquid</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Hash: {&quot;key&quot;:&quot;value&quot;,&quot;key2&quot;:&quot;value2&quot;,&quot;key3&quot;:&quot;value3&quot;}
</pre></div>
</div>
<p><hr></p>
</section>
<section id="values">
<h2>values<a class="headerlink" href="#values" title="Link to this heading"></a></h2>
<p>Takes a hash and returns the array of its values.</p>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit d52062b

Please sign in to comment.