android.moparisthebest.org/source/docs/plugins/puts/index.markdown

63 lines
1.6 KiB
Markdown
Raw Normal View History

2012-05-22 17:28:56 -04:00
---
layout: page
title: "Puts - log from Liquid to the terminal"
date: 2011-07-22 09:14
sidebar: false
footer: false
---
Puts is a Liquid block which outputs its contents to your terminal with Ruby's `puts` command. This really handy when you're working on a Liquid tag or a Jekyll plugin and you want to to be able to peek behind the curtain at what Liquid sees.
#### Syntax
{% raw %}
2012-05-22 17:28:56 -04:00
{% puts %}Optional Text: {{ some_liquid_variable }}{% endputs %}
{% endraw %}
2012-05-22 17:28:56 -04:00
This just outputs the contents of the block to the terminal. Note: Markdown, Textile and other converters run after liquid, so depending on where you use the block, you may see raw templating markup, not processed html.
2012-05-22 17:28:56 -04:00
#### Example 1
{% raw %}
2012-05-22 17:28:56 -04:00
{% for post in site.posts %}
{% puts %}Title: {{ post.title }}{% endputs %}
{% endfor %}
{% endraw %}
2012-05-22 17:28:56 -04:00
#### Output:
{% raw %}
2012-05-22 17:28:56 -04:00
```
{% puts %} Title: Hello World, I just switched to Octopress
{% puts %} Title: Zombie Ninjas Attack: A survivor's retrospective
...
```
{% endraw %}
2012-05-22 17:28:56 -04:00
#### Example 2 - Longer content
If a line of output is wider than 80 characters it gets output in a puts block for easier marking.
{% raw %}
2012-05-22 17:28:56 -04:00
{% for post in site.posts %}
{% puts %}
Title: {{ post.title }}
Content: {{ post.content }}
{% endputs %}
{% endfor %}
{% endraw %}
2012-05-22 17:28:56 -04:00
#### Output
{% raw %}
2012-05-22 17:28:56 -04:00
```
{% puts %}
Title: Zombie Ninjas Attack: A survivor's retrospective
Content: Spoiler: You don't want to survive this. So there I was, standing in line
for a movie. I could hear hear some car alarms going off in the distance, but that
....
{% endputs %}
```
{% endraw %}
2012-05-22 17:28:56 -04:00
[« Plugins page](/docs/plugins)