kolber / stacey

Cheap & easy content management
http://staceyapp.com
MIT License
1.04k stars 131 forks source link

How to use Twig trim filter? {{ page.variable | trim(",") }} #101

Closed o-l-e closed 11 years ago

o-l-e commented 11 years ago

I have created a variable in my project.txt that looks like this:

title: Project Title 1
tags: website, web, site

Then i try to trim the "," in order to inject the result into a class like this:

<div class="{{ page.tags|trim(",") }} ">Project Title 1</div>

For some reason it does not trim the commas. Am i doing this wrong, or is this filter not possible in Stacey?

Thanks.

mjau-mjau commented 11 years ago

The trim filter strips whitespace (or other characters) from the beginning and end of a string. It does not remove items from inside the string: http://twig.sensiolabs.org/doc/filters/trim.html

What are you trying to do? Just remove the , comma? You could use split or replace filters: http://twig.sensiolabs.org/doc/filters/split.html http://twig.sensiolabs.org/doc/filters/replace.html

I don't know if Stacey updated to the latest Twig yet though, so not quite sure what filters are available to use.

o-l-e commented 11 years ago

Hey Karl thank you so much, the replace filter worked like this:

Tags: {{ page.tags|replace({"," : ""}) }}

What i was trying to do was remove the comma. Sorry about asking stupid questions. I am really not comfortable with twig yet, i am still learning, so i really appreciate the help here.

Ps: I did do an update of the Twig parser like referenced here: https://github.com/kolber/stacey/pull/91 So i don't know if the replace filter will work with the current version of Stacey(have not tried).