Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
o-l-e opened this issue Sep 18, 2013 · 2 comments
Closed

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

o-l-e opened this issue Sep 18, 2013 · 2 comments

Comments

@o-l-e
Copy link

o-l-e commented Sep 18, 2013

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
Copy link

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
Copy link
Author

o-l-e commented Sep 18, 2013

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: #91
So i don't know if the replace filter will work with the current version of Stacey(have not tried).

@o-l-e o-l-e closed this as completed Sep 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants