I'm struggling to understand a step in my lecture notes.
Given a scalar field $f: \mathbb{R}^n \to \mathbb{R}$ and a function $\phi: \mathbb{R} \to \mathbb{R}$, \begin{align} \underline{\nabla} \phi &= \underline{e}_1 \frac{\partial \phi}{\partial x_1} + \dots + \underline{e}_n \frac{\partial \phi}{\partial x_n} \\ &= \underline{e}_1 \frac{\partial f}{\partial x_1} \frac{d \phi}{d f} + \dots + \underline{e}_n \frac{\partial f}{\partial x_n} \frac{d \phi}{d f} \\ &= (\underline{\nabla} f) \frac{d \phi}{df}.\end{align}
The problem is, I don't understand the second line, why is it that $$\frac{\partial \phi}{\partial x_1} = \frac{\partial f}{\partial x_1} \frac{d \phi}{d f} ?$$
It seems similar in format to the chain rule, but I just don't understand where it has come from.
This is because of the chain rule. You can write down a function as:
$$ \phi(x)=\phi \big(f(x) \big) \tag 1$$
Now simply use the chain rule:
$${d \phi \big(f(x)\big) \over dx} = {d \phi \over df }{d f \over dx } \tag 2$$
We can derive your end formula step by step. The gradient operator is defined as:
$$ \mathrm{grad} (\cdot)= \vec{\nabla} = { \partial \over \partial x_1 } \hat e_1 + { \partial \over \partial x_2 } \hat e_2 + ... { \partial \over \partial x_n } \hat e_n \tag 3 $$
Applying the gradient to $\phi(x_1,x_2...x_n)=\phi \big (f(x_1,x_2...x_n) \big)$ gives:
$$ \mathrm{grad}\bigg( \phi \big (f(x_1,x_2...x_n) \big) \bigg) = {\partial \phi \over \ \partial f}{ \partial f\over \partial x_1 } \hat e_1 + {\partial \phi \over \ \partial f}{ \partial f\over \partial x_2 } \hat e_2 + ... {\partial \phi \over \ \partial f}{ \partial f \over \partial x_n } \hat e_n \tag 4$$
$$ \mathrm{grad}\bigg( \phi \big (f(x_1,x_2...x_n) \big) \bigg) = {\partial \phi \over \ \partial f}\Bigg ({ \partial f\over \partial x_1 } \hat e_1 + { \partial f\over \partial x_2 } \hat e_2 + ... { \partial f\over \partial x_n } \hat e_n \Bigg )\tag 5$$
$$ \mathrm{grad}\bigg( \phi \big (f(x_1,x_2...x_n) \big) \bigg) = {\partial \phi \over \ \partial f} \mathrm{grad}(f)= {\partial \phi \over \ \partial f} \vec{\nabla} f\tag 6$$
Now, since we can say $\phi = \phi(f)$, that means we can write down:
$$ {\partial \phi \over \ \partial f} = {d \phi \over \ d f} \tag7 $$
This gives us the final result:
$$ \mathrm{grad}\bigg( \phi \big (f(x_1,x_2...x_n) \big) \bigg) = {d \phi \over \ d f} \mathrm{grad}(f)= {d \phi \over \ d f} \vec{\nabla} f\tag8 $$
I also suggest you research the term total derivative.