Open alexroper opened 7 years ago
I experienced this too in using "contains" to check for an "@" symbol for determining if an entry was an email address.
@alexroper @castirondesign does anything work with start_with using this syntax, for you?
{{ if foo starts_with="bar" }}
I don't think anything will work using that syntax inside a condition.
OK, just an error in the docs then.
How do you get that to work in a conditional, assuming you can use starts_with:foo (i.e. you need a space or to use a variable)?
In that situation you might need to make a tag.
I've tinked on this a while and it's a deficiency in the Parser. It works in general with |
pipe syntax modifiers but not parameters. However, the pound sign is treated as a PHP comment, so it gets stripped and it explodes. It's a pretty tricky bug to fix unfortunately. I do plan to make some updates to the parser in the near future so we'll see if it can get tackled then.
In the meantime, just use: {{ if hashtag|urlencode|starts_with:%23 }}
Expected behaviour
If a variable
hashtag
has a value of#bugs
, the starts_with conditional should be able to test if the hash character at the beginning of the string.For example this code:
or...
Should output:
Actual behaviour
This:
... Returns a false value (nothing is output).
This on the other hand:
... Triggers and error: "ParsingException in Parser.php line 1221: You have a syntax error in your Lex tags."
Server configuration
Operating system: Mac OS 10.10.5
Web server: Apache
PHP version: 5.6.10
Statamic version: 2.1.17
Updated from an older Statamic or fresh install: updated
List of installed addons: none
Logs
If any logs (browser, server, or Statamic) are appropriate...