Directives 101
We've now done some thinking and want to give our users an id instead of identifying them by email address. We're also a bit bored of seeing the same admin email address again and again.
Let's update our factory again:
Now things are getting more interesting! We've introduced our first directives - special instructions to fabrikk.
The sequence
directive provides an increasing series of integers. Perfect for giving each user a unique id:
I said directives plural above, so where's the other one? Well, technically, functions are directives too! When a template value is a zero argument function, fabrikk will invoke that function at build time and set the key to the return value.
Note that the admin-email function was specified in a trait, the following is true in general:
Anything that works for a template will work when specified in a trait.
Note that functions don't allow you to access the entity you're building, in the next section we'll cover another directive that lets you do that.
Last updated