Template Help Selection

Hello all,

I feel like im SUPER close to getting this to work,
I have a template that I want to select line(s) of text its usually code.

I would then like to wrap this with the 3 `'s

'''CodeType
#Code that is selected will be here
'''

I’m not sure when I should use tR vs <% %>
I believe that is my problem. If anyone has a little explaination id love to hear it.

Here is what I have.
Currently the code was running without errors but not doing what its suppose to. It was displaying the

if (code !== null) {
    tR = 
    ``` ${code} 
    ${ tp.file.selection() }
    ```
}

Now I changed the code to this:

<%* 
let code = await tp.user.chooseCodeBlock(tp);

if (code !== null) {
    tR = 
    ``` ${code} 
    ${ tp.file.selection() }
    ```
}
%>

and it says

Templater Error: Template parsing error, aborting.
“” is not a function

Thank you