pattern-lab / plugin-php-faker

The Faker Plugin adds Faker support to Pattern Lab.
http://patternlab.io/
MIT License
7 stars 16 forks source link

Faker doesn't work in Pattern Data Files, but does in global data #2

Open EvanLovely opened 8 years ago

EvanLovely commented 8 years ago

I'm only able to get Faker to work in the global data file, and not in the pattern specific data files. So I've got something like this in source/_data/data.json: "name": "Faker.firstName" and it works, but not in authors.json when next to authors.twig.

This is a super helpful plugin, thanks!!!

dave-cross commented 8 years ago

I wasn't able to get it working either. Very strange.

Luckily, I was able to get the default filter working (I'm using the Twig edition). I used my original faker function from here: https://github.com/pattern-lab/edition-php-twig-standard/issues/7

Don't run the composer command. Just make the faker.function.php file. Then, in my Twig file, I call {{ myvar|default(faker('name')) }}. If variable is filled in the json file, you get that info. Otherwise, you get the default "faker" info.

EvanLovely commented 8 years ago

That's a great workaround! I'll probably end up using that where needed; thanks so much! I've got a lot of Faker data in my global data.json file for vars used in lots of places that are really helpful: https://github.com/phase2/pattern-lab-starter/blob/master/source/_data/data.json

dave-cross commented 8 years ago

Awesome! Thanks for showing me (us?). I'm only just getting back into this (too many months on print projects), but I'm also glad they're building Faker into patternlab. Cheers!

remydenton commented 7 years ago

The workarounds go a long way, but it would be ideal if we could just get faker working in pattern-specific data files. @dmolsen, any plans to support that or thoughts on how best to approach it? I know there are plugins out there that support that kind of per-pattern data replacement (e.g. data-transform). I'm curious whether you considered a similar approach and decided against it or just haven't had a chance to try it.

sh-avonis commented 5 years ago

The provided PR #7 worked for me. Please consider a merge.