Strip Liquid Tags

<meta name="description" content="{% if page.description %}{{ page.description }}{% else %}{{ page.content | strip_html | strip_newlines | truncate: 160 }}{% endif %}">

Using the above logic, I’m getting the following output:

Lorem ipsum dolor sit amet, consectetur adipiscing.{% for lorem in site.ipsum %} {{ lorem.title }}{% endfor %}

How can I strip the Liquid from this output?

where is the for statement coming from? is that in the page content?

Not sure you will be able to strip that easily, and there are probably other use cases where you will get something unintended. When I do the description if there is no page description I put in a generic site.deescription - and make sure that I always have a page description.

It’s in a regular page (.md file), which is acting like a category page for a collection.

Historically I’ve done the site.description call as a fallback, but it doesn’t work well in a lot of cases so I’m looking for something more relevant when a page description isn’t provided in front-matter.

Have you tried page.excerpt? That might strip it.
It also has the benefit of being overidded. If you don’t like the excerpt Jekyll automatically creates you can manually add it to the page’s front matter

excerpt: "I like this excerpt better than the automatically generated one."

page.excerpt doesn’t return anything. Per the docs, that is a default Jekyll function, but I can’t get it to work.

Did you try adding YAML front matter to a page like above to see if it returns something?

It’s possible that Jekyll’s auto excerpt function only works with _posts.

If I manually add excerpt: "I like this excerpt better than the automatically generated one." to the page’s front-matter, then yes, it will display “I like this excerpt better than the automatically generated one.” when I call page.excerpt.

Well, you’re right, looks like excerpts only work in posts. I did some testing and I can get the liquid for loop to work in a post, and post.excerpt works as expected.

Any ideas on how to spoof this in _pages?

It would need to be added to Jekyll core or built as a plugin. Looks like it was discussed awhile back in this issue, but went stale.

Looks like it was added to the 4.0 milestone last April. I’ll keep an eye out for that. Thanks for the help Michael.