survos/faker-bundle

Makes fakerphp/faker methods available via twig

Fund package maintenance!
kbond

Installs: 115

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.5.394 2024-11-19 14:35 UTC

This package is auto-updated.

Last update: 2024-11-21 23:47:20 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 config allow-plugins.survos/installer true
composer req survos/faker-bundle
echo "{% extends 'base.html.twig' %} {% block body %}<ul> {% for i in 0..10 %} <li>{{ person_name() }} <u>{{ internet_email() }}</u> <br />  <i>{{ company_jobTitle() }}</i>, {{ company_company() }}  </li>{% endfor %}</ul> {% endblock %}" > templates/app/index.html.twig
symfony server:start -d
symfony open:local

symfony new pwa-demo --webapp --php=8.2 && cd pwa-demo composer config extra.symfony.allow-contrib true composer req symfony/stimulus-bundle

bin/console make:controller AppController sed -i "s|Route('/app'|Route('/'|" src/Controller/AppController.php sed -i "s|'app_app'|'app_homepage'|" src/Controller/AppController.php cat > templates/app/index.html.twig <<END {% extends 'base.html.twig' %} {% block body %}

A simple CRUD

Listing {% endblock %} END

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