Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output Available Objects and Properties in Liquid Templates

Is there a way to output (for debugging/informational purposes) the available objects and object properties in a liquid template?

That is, say I'm using the jekyll site generation tool, and I'm in my index.html template (which is, to my understanding, a liquid template). It might look something like this

{% for post in site.posts %}
  <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}

Are there any template tags I could use that would tell me/output a variable named post was available in this template (as well as the other templates). Also, are there any template tags I could use that would tell me the post object has the keys date, title, url, excerpt, permalink, etc.

like image 592
Alan Storm Avatar asked Aug 25 '13 20:08

Alan Storm


People also ask

What are Liquid objects?

any object consisting of at least 2 % by particle, or least divisible particle, number of liquids is called a liquid object.

What are Liquid templates?

Liquid is an open-source template language integrated into portals. It can be used to add dynamic content to pages, and to create a wide variety of custom templates. Using Liquid, you can: Add dynamic content directly to the Copy field of a webpage or the content of a content snippet.

What is Liquid template engine?

Liquid is a template language that allows us to display data in a template. Liquid has constructs such as output, logic, loops and deals with variables. Liquid files are a mixture of HTML and Liquid code, and have the . liquid file extension.

What is object in Shopify?

An object in Shopify is a data entity that represents a specific thing in your shop, such as a product, a collection, or an order. Objects can have their own unique properties and can be linked to other objects. For example, products can be linked to collections and orders.


1 Answers

There's no way to do this from a Liquid template that I'm aware of. I used the following bit of Ruby code to do it in a test for Jekyll though (setup_post is a helper method in Jekyll's test suite)

post = setup_post("2008-11-21-complex.textile")
classes = []
Liquid::Template.parse(post.content).root.nodelist.each do |token|
  classes << token.name if token.is_a?(Liquid::Variable)
end

It should be possible to write a Jekyll plugin that could output this stuff on your page based on the above code.

like image 81
mattr- Avatar answered Oct 05 '22 23:10

mattr-