Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EvanLovely opened this issue Aug 31, 2016 · 5 comments
Open

Comments

@EvanLovely
Copy link
Member

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
Copy link

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.

@EvanLovely EvanLovely changed the title Faker doesn't work in Pattern Data Files Faker doesn't work in Pattern Data Files, but does in global data Sep 3, 2016
@EvanLovely
Copy link
Member Author

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
Copy link

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
Copy link

remydenton commented Jun 27, 2017

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.

AndyIRC pushed a commit to AndyIRC/plugin-php-faker that referenced this issue Aug 3, 2018
@sh-avonis
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants