I use Jekyll on GitHub pages to create a blog and want to get the length of the page.title string passed to the Liquid template in the YAML control in each post. I could not find an easy way to do this. Looking at the Guide for Liquid For Designers , I could see that it supports two types of markup:
Markup output . Separated by double curly braces {{ }} , you can display the variables that are passed to your template, either in the front of the YAML, for example page.title in Jekyll, or global site-level variables in _config.yml . To display the title of a message or page, you must use {{ page.title }} .
Tagging Indicates braces and percentages {% %} , they are used for logic in your templates. If statements, loops, this type of thing.
There are apparently a lot of filters that you can use with Output Markup, and you can output the length of the string passed to the template using {{ page.title | size }} {{ page.title | size }} .
However, what I would like to do in my template displays the page title using the header <h1> , <h2> or <h3> depending on the length of the header.
I still can't figure out tagging and output markup.
I can display the size of page.title on a page with {{ page.title | size }} {{ page.title | size }} , but I cannot, however, figure out how to use length in an if statement. It also returns a string representation, not a number.
Does anyone with more experience with Liquid know how to do this?
Ideally, what I would like to do is something like this:
{% if page.title | size > 5 %}
source share