Tower
Tower

Reputation: 102785

Symfony2 YAML parsing fails

I have this content in YAML:

Foo:
    bar:    |
            Foo bar.

And it works fine, but this:

Foo:
    bar:    |
            40 % Foo bar.

Fails:

ParameterNotFoundException: The parameter "foobar" has a dependency on a non-existent parameter " Foo bar.".

Based on the error, it clearly occurs right where the percent sign % appears. Is there some way to encode it or make it not fail?

Upvotes: 2

Views: 1675

Answers (3)

Aurelijus Rozenas
Aurelijus Rozenas

Reputation: 2247

So in short, use %% when you want % in yaml value.

Upvotes: 2

DaleA
DaleA

Reputation: 31

As per http://symfony.com/doc/current/reference/configuration/framework.html

All percentage signs (%) in the format string must be doubled to escape the character. Without escaping, values might inadvertently be interpreted as Service Parameters.

Upvotes: 1

Aldo Stracquadanio
Aldo Stracquadanio

Reputation: 6237

The problem is that the %something% syntax is used by Symfony Dependency Injection Container to reference DIC parameters. I think that you should somehow escape the %; as a first try I would go for one of those:

40 %% Foo bar .
40 "%" Foo bar .
"40 % Foo bar ."

I didn't find a 100% sure answer in Symfony, so go for tries ;)

Upvotes: 2

Related Questions