Skip to content

Commit

Permalink
[ODE-12] Added metaobject detector snippet (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
blanklob authored Sep 10, 2023
1 parent 6e21b62 commit 0b5e94d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can navigate these snippets by using the table below.
| Category | Snippet | Description |
| --- | --- | --- |
| [Tools](#tools) | [Development screen indicator](#development-screen-indicator) | A simple indicator that shows which viewport size you are in. Useful for debugging and development.
| [Tools](#tools) | [Metaobject detector](#metaobject-detector) | A way to detect the current metaobject on the metaobject template without relying on dynamic ressources.
| [Meta](#meta) | [Social share](#social-share) | A small snippet to render all necessary meta tags for social sharing and page previews on socials. |
| [UI](#ui) | [Image](#image) | A powerful, less opinionated image snippet built on top of evergreen web technologies for Shopify storefronts. |
| [Schemas](#schemas) | [Schema Website](#schema-website) | Renders the schema.org website JSON-LD for Site Name. |
Expand All @@ -50,9 +51,9 @@ Built with [Tailwind CSS](https://tailwindcss.com) and can be added on the `them
Copy code from [this file](./tools/development-screen-indicator.liquid).

```liquid
{% liquid
{% liquid
if settings.enable_development_mode
render 'development-screen-indicator'
render 'development-screen-indicator'
endif
%}
```
Expand All @@ -68,6 +69,18 @@ An example of a setting to enable the development screen indicator on demand:
}
```

### Metaobject detector

This must be used inside a metaobject template. It detects the current metaobject and renders its properties or other metaobjects if it has any.

Copy code from [this file](./tools/metaobject-detector.liquid).

```liquid
{% render 'metaobject-detector' %}
```

Learn more about metaobject templates [here](https://shopify.dev/docs/themes/architecture/templates/metaobject).

## Meta

These are snippets that render meta tags to enhance the storefront with additional information.
Expand Down
14 changes: 8 additions & 6 deletions tools/metaobject-detector.liquid
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% comment %}
A way to detect metaobject on the current metaobject
A way to detect the current metaobject on the metaobject
template without relying on dynamic ressources.
Usage:
Expand All @@ -9,11 +9,13 @@
{% liquid
assign current_metaobject = null

for metaobject in shop.metaobjects[template.name].values
if request.page_type == 'metaobject' and request.path contains metaobject.system.handle
assign current_metaobject = metaobject
endif
endfor
if request.page_type == 'metaobject'
for metaobject in shop.metaobjects[template.name].values
if request.path contains metaobject.system.handle
assign current_metaobject = metaobject
endif
endfor
endif
%}

{% if current_metaobject != null %}
Expand Down

0 comments on commit 0b5e94d

Please sign in to comment.