advice on freemarker templating, want to create a master template

Yes, it's possible. In our applications things like the user object exist in session scope, but this could be any scope freemarker has access to:

<#if Session.the_user?? && Session.the_user.loggedIn>
    <#-- header code -->
</#if> 

You can omit the Session. and Freemarker will search the various scopes for the given variable name.

To inject the content, include this at the point in the master template where you'd like the view page to put its content:

<#nested>

The view pages then declare their use of the master template as follows:

<#import "/WEB-INF/ftl/path/to/template/master.ftl" as com>
<@com.template>
    View page content
</@com.template>

I made Freemarker template inheritance - https://github.com/kwon37xi/freemarker-template-inheritance I think it's what you want. It is tested on freemarker 2.3.19.