survos/faker-bundle

Makes fakerphp/faker methods available via twig

Fund package maintenance!
kbond

Installs: 111

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.5.378 2024-06-30 10:53 UTC

This package is auto-updated.

Last update: 2024-11-04 17:03:18 UTC


README

Symfony Bundle for fakerphp/faker, exposes many of the formatters in twig.

composer req survos/faker-bundle
<ul>
{% for i in 1..10 %}
<li>{{ person_name() }}, {{ company_company() }}</li>
{% endfor %} 
</ul>

By default, the data will change with every page refresh. To keep it consistent, change the seed. If the twig function names interfere with another twig function, set a prefix, e.g. fake_name().

# config/packages/survos_faker.yaml
survos_faker:
  seed: 42
  prefix: fake_

You can also set the seed in a twig file, via the faker_set_seed() function.

Working example

Cut and paste the following to create a new Symfony project with a landing page that demonstrates the faker twig functions.

symfony new FakerDemo --webapp && cd FakerDemo
bin/console make:controller AppController
sed  -i "s|'/app'|'/'|" src/Controller/AppController.php # the landing page controller
composer req survos/faker-bundle
echo "<ul> {% for i in 0..10 %} <li>{{ person_name() }} <u>{{ internet_email() }}</u> <br />  <i>{{ company_jobTitle() }}</i>, {{ company_company() }}  </li>{% endfor %}</ul>" > templates/app/index.html.twig
symfony server:start 

Now open the site. Each refresh generates different results. To make the results consistent, set a seed.

echo "survos_faker: {seed: 1}" > config/packages/survos_faker.yaml
bin/console cache:clear
symfony server:start