Coder Social home page Coder Social logo

shopify-shortcodes's Introduction

Shopify Shortcodes

The purpose of this project is to make advanced html usage available to store owners. This project can simplify galleries, faq, maps, videos and more for the store owner.

Syntax

So quickly some information on syntax. We have tried to keep the system consistent with Wordpress so an example tag is

[youtube width="800" height="500" video="M7lc1UVf-VE"]

The first part is the snippet it is going to load and the rest are variables that you can use within the snippet

The above example will load the snippet shortcode-youtube.liquid from your snippet folder.

It will then pass the variables width, height and video with the respective values.

Accessing variables in snippets

These variables are available to the snippet by using

{% include 'shortcode-render' render:'width' default:'640' %}

For easy reuse you can simply capture the result in to your own variable with

{% capture youtubeWidth %}{% include 'shortcode-render' render:'width' default:'640' %}{% endcapture %}

Naming convention

All shortcodes are prefixed in the file system with shortcode- so make sure that if you want a shortcode of youtube you create a shortcode-youtube.liquid file.

The purpose of this is to allow store owners to easily find all active shortcodes within a store and avoid collisions with other snippets.

Examples

The youtube example used is available in the examples directory of this project. If you have created a shortcode you would like to share feel free to create a pull request and we will add it in.

Activating shortcodes

You must first copy shortcode.liquid and shortcode-render.liquid in to your snippets.

To activate shortcode functionality a change to liquid tags is required where the functionality is required.

{{ page.content }}

Would need to be changed to

{% include 'shortcode' load: page.content %}

Shortcode fallback display

As shopify data can be sent to external applications and used in places where the shortcode is unable to render an optional syntax is available.

It plays on the fact the display of the data will more than likely be in a HTML page and uses the default HTML comment tag to hide the shortcode in places where it has not been rendered.

<!--[youtube width="800" height="500" video="M7lc1UVf-VE"]-->

Using this syntax will however hide it from the WYISWYG editor and make editing by store owners more difficult.

Brackets in content

You may be thinking what happens if I have square brackets in other parts of my content. Not to worry the plugin will only replace square bracket content if it finds an active shortcode. For example

[ Random Content ]

The above won't be replaced with new content unless a shortcode with the name Random exists. There are rare cases when the word you use is a shortcode and this will need to be fixed manually such as

[ youtube is a great channel ]

Would need to be replaced by something such as

( youtube is a great channel )

shopify-shortcodes's People

Contributors

evulse avatar ryanheart avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.