sed/awk to insert multiple lines before pattern

I'm attempting to insert multiple lines before a line matching a given search pattern. These lines are generated in a separate function and can either be piped in as stdout or read from a temporary file.

I've been able to insert the lines from a file after the pattern using:
sed -i '/pattern/ r tempfile' file
I also know I can insert a line or lines before a pattern using:
sed -i '/pattern/i lines' file

I have yet to find an answer as to how to combine the two. Other options I've considered include finding the line number, subtracting one, then inserting the file after that line. I would be open to using awk or grep or any combination of these.

An example how to insert "tempfile" after line 50 and insert a line before a pattern using variables:

awk -v file="tempfile" -v line="Your line" -v lineno=50 -v pattern="yourpattern" '
NR==lineno {print; system("cat " file); next}	# print the file after line 50
$0 ~ pattern {print line}			# print the line before pattern
1' file

--------