Reputation: 3076
I have a PhpStorm Php file template under Editor > File and Code Templates:
According to the linked Apache Velocity Docs to escape a dollar sign a back slash should be used:
<?php
declare(strict_types=1);
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class ${NAME} implements DataTransformerInterface
{
public function __construct()
{}
public function transform(\$value)
{
return ;
}
}
But when I select the template when creating a class, the backslash stays:
File output:
<?php
declare(strict_types=1);
namespace SomeProject\SomeBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class TestTransformer implements DataTransformerInterface
{
public function __construct()
{}
public function transform(\$value)
{
return ;
}
public function reverseTransform()
{
return ;
}
}
It works when i directly select the template and not create class, but then the namespace is not taken automatically...
Upvotes: 7
Views: 1237
Reputation: 165118
As per PhpStorm help page (link below) the best way would be to use predefined ${DS}
variable if you need to have $
(dollar sign) in the file template output.
https://www.jetbrains.com/help/phpstorm/file-template-variables.html
Upvotes: 3