Peter Rehm's Blog

apple,development,life & more

Symfony2 Render String with Twig

Ohne Kommentare

At some point you might find the need to render templates from an string rather
than an actual file. This is needed for dynamic templates.

This is not possible with the default Symfony2 configuration, however it is easy to
adjust the configuration.

I ended up adding the Twig_Loader_String to the Loader chain with teh following
service configuration:

CODE:
    newi.core.twig.stringloader:
        class: Twig_Loader_String
        tags:
            - { name: twig.loader }


With having this small snippet in the service.yml of one of your bundles you can
render strings with the normal twig instance from the DI container.

CODE:
    $renderedString = $this->get('twig')->render('Hello my name is {{ name }}!', array($name => 'Peter'));

Geschrieben von Peter Rehm

26.05.2014 um 13:32:35

Tags für diesen Artikel: , ,

Symfony2 Ordered Fixtures

Ohne Kommentare

If you want to set the order in which the Fixtures are boing loaded there are
two steps:

- Use the AbstractFixture Interface

CODE:
class LoadCompanyData extends AbstractFixture implements OrderedFixtureInterface


- Add getOrder Methode

CODE:
public function getOrder()
{
    return 1;
}


Than it will work.

Geschrieben von Peter Rehm

17.10.2012 um 19:33:40

Tags für diesen Artikel: ,

Symfony2 Permissions on Mac

Ohne Kommentare

To configure the permissions on mac use the following commands:


sudo rm -rf app/cache/
sudo rm -rf app/logs/

sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "yourusername allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

Geschrieben von Peter Rehm

17.10.2012 um 19:31:39

Tags für diesen Artikel: ,