pattern-lab/plugin-php-faker

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

EvanLovely opened this issue · 5 comments

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!!!

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: pattern-lab/edition-php-twig-standard#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.

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

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!

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.

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