Skip to content

Commit 6382abb

Browse files
committed
render tag completed, readme updated, fixed #45
1 parent 335d0be commit 6382abb

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

readme.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,22 @@ If you don’t want any of your tags to print whitespace, as a general rule you
9797

9898
## Variable Scope & Components
9999
This is not unique to this project but it's worth mentioning and creating a component example. See the `src/components/snippets/dynamic-modal/dynamic-modal.liquid` component. This is a simple modal that uses variable scope for data, styles and functions.
100-
In this file we assign some default variables.
101-
```html
102-
{%- assign id = "defaultModal" -%}
103-
{%- assign openModalBtn = "defaultOpenButton" -%}
104-
{%- assign title = "Modal Title" -%}
105-
{%- assign body = "Modal Body" -%}
106-
```
107-
Use this `dynamic-modal.liquid` component by creating a trigger element like a button with an id.
100+
Use this `dynamic-modal.liquid` component by creating a trigger element or function like a button with an id.
108101
```html
109102
<button id="testButton">Trigger Modal</button>
110103
```
111104
Next we include the modal in a section with declared variables. These will be scoped to the snippet and we now have a dynamic reusable modal component we can use throughout our theme.
112105
```html
113-
{%- include "dynamic-modal",
114-
id: "homePageTestModal",
115-
openModalBtn: "testButton",
116-
title: "Testing Title Variable",
117-
body: "Testing the Dynamic Body Of the Modal...",
118-
buttonOne: "Alert",
119-
buttonOneFunction: "alert('Q: Do you struggle with impostor syndrome? Me: no I’m great at it')"
120-
buttonTwo: "Close",
121-
buttonTwoStyle: "text-white bg-red-500 hover:bg-red-700"
122-
buttonTwoFunction: "modal.style.display = 'none';"
106+
{%- render 'dynamic-modal',
107+
id: "testModal",
108+
openModalBtn: "modalBtn",
109+
title: "Modal Title",
110+
body: "Modal Body",
111+
buttonOne: "Alert",
112+
buttonOneFunction: "alert('Q: Do you struggle with impostor syndrome? Me: no I’m great at it')"
113+
buttonTwo: "Close",
114+
buttonTwoStyle: "text-white bg-red-500 hover:bg-red-700"
115+
buttonTwoFunction: "modal.style.display = 'none';"
123116
-%}
124117
```
125-
Read more on this [Shopify Variable Scopes](https://ellodave.dev/blog/2019/5/24/shopify-variable-scopes/). If you find some good use cases for these please post them in the [discussion ideas category](https://github.com/3daddict/themekit-webpack/discussions/categories/ideas)
118+
I came across this idea using `include` from [David Warrington's](https://github.com/davidwarrington) article [Shopify Variable Scopes](https://ellodave.dev/blog/2019/5/24/shopify-variable-scopes/) and re-factored to use `render` tags. If you find some good use cases for these please post them in the [discussion ideas category](https://github.com/3daddict/themekit-webpack/discussions/categories/ideas)

src/components/snippets/dynamic-modal/dynamic-modal.liquid

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
{%- comment -%}
22
This snippet uses Variable Scope and can be re-used throughout the theme.
3-
To use this snippet in sections, add {%- include, key: value -%} with some assigned variables.
3+
To use this snippet in sections, add {%- render, key: value -%} with assigned variables.
44
For Example:
5+
This is the target button id that will open the modal.
6+
<button id="modalBtn">TEST MODAL</button>
57
=========================================================================
6-
{%- include "dynamic-modal",
7-
id: "homePageTestModal",
8-
openModalBtn: "testButton",
9-
title: "Testing Title Variable",
10-
body: "Testing the Dynamic Body Of the Modal..."
8+
Here is a render tag example to use in the section with some example variables declared.
9+
Note the openModalBtn matches the button element above which triggers the modal in this example.
10+
=========================================================================
11+
{%- render 'dynamic-modal',
12+
id: "testModal",
13+
openModalBtn: "modalBtn",
14+
title: "Modal Title",
15+
body: "Modal Body",
16+
buttonOne: "Button One",
17+
buttonOneStyle: "text-white bg-blue-500 hover:bg-blue-700",
18+
buttonOneFunction: "javascript:void(0);",
19+
buttonTwo: "Button Two",
20+
buttonTwoStyle: "text-white bg-transparent hover:bg-blue-700 text-blue-500 hover:text-white border border-blue-500 hover:border-transparent",
21+
buttonTwoFunction: "javascript:void(0);"
1122
-%}
1223
=========================================================================
13-
These 👆 will change the default assignments below 👇
24+
id, openModalBtn, title and body are required. If you don't want buttons make the value = null.
25+
=========================================================================
1426
{%- endcomment -%}
15-
{%- assign id = "defaultModal" -%}
16-
{%- assign openModalBtn = "defaultOpenButton" -%}
17-
{%- assign title = "Modal Title" -%}
18-
{%- assign body = "Modal Body" -%}
19-
{%- assign buttonOne = null -%}
20-
{%- assign buttonOneStyle = "text-white bg-blue-500 hover:bg-blue-700" -%}
21-
{%- assign buttonOneFunction = "javascript:void(0);" -%}
22-
{%- assign buttonTwo = null -%}
23-
{%- assign buttonTwoStyle = "text-white bg-transparent hover:bg-blue-700 text-blue-500 hover:text-white border border-blue-500 hover:border-transparent" -%}
24-
{%- assign buttonTwoFunction = "javascript:void(0);" -%}
2527

2628
<section class="hidden" id="{{ id }}">
27-
<div class="flex items-center justify-center fixed left-0 bottom-0 w-full h-full bg-black bg-opacity-75" id="modalContainer">
29+
<div class="flex items-center justify-center fixed left-0 bottom-0 w-full h-full bg-black bg-opacity-75 z-50" id="modalContainer">
2830
<div class="bg-white rounded-lg w-1/2">
2931
<div class="flex flex-col items-start p-4">
3032
<div class="flex items-center w-full">

0 commit comments

Comments
 (0)