2

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?

3 Answers 3

2

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

The last would be the correct way of doing it. Also note that a non-escaped % can cause errors if you ever parse your yaml with non-symfony parsers.
2

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.