I guess there are two possible ways to add the header automatically and use user definable values. The first and easier way is to force the user to provide the information before typesetting the header, i.e. use \schoolname{My School} in the preamble:
\documentclass{myclass}
\schoolname{My School}% OK
\begin{document}
%\schoolname{My School}% ERR
Document content
\end{document}
This can be done by redefine \schoolname to caus en error when it is used after \begin{document}:
\ProvidesClass{myclass}
% base class
\LoadClassWithOptions{article}
% define the value macros
\newcommand{\@schoolname}{}
\newcommand{\schoolname}[1]{\gdef\@schoolname{#1}}
% ... etc ...
% provide the error message
\newcommand{\mycls@headerror}{%
\ClassError{myclass}{Must be in preamble}{...}%
}
% define the hook
\AtBeginDocument{%
{\centering\bfseries\sffamily
\@schoolname
\par}
\vspace{\baselineskip}
\hrule
\vspace{\baselineskip}
\let\schoolname\mycls@headerror
}
Prerequisites: none
Steps to create a new command:
Define the macro to store the value \@<name>, e.g.
\newcommand{\@schoolname}{}
Define the macro to set the value \<name>, e.g.
\newcommand{\schoolname}[1]{\gdef\@schoolname{#1}}
Add the value (via \@<name>) to your header, e.g.
{\centering\bfseries\sffamily
\@schoolname
\par}
Redirect the setting macro (\<name>) to cause an error, after the header is typeset
\let\schoolname\mycls@headerror
The second way is to give the values as class options. I used kvoptions to realize class options with values. The use must define the values via class options:
\documentclass[%
schoolname={My School}
]{myclass}
\begin{document}
Document content
\end{document}
And thats how you can process it:
\ProvidesClass{myclass}
% load package and set it up
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=MC,% MC = my class
prefix=my@% prefix to macros holding the values
}
% define the keys
\DeclareStringOption{schoolname}
% ... etc. ...
% Process the options
\ProcessKeyvalOptions*
% base class
\LoadClass{article}
% define the hook
\AtBeginDocument{%
{\centering\bfseries\sffamily
\my@schoolname% acces values by \<prefix>@<keyname>
\par}
\vspace{\baselineskip}
\hrule
\vspace{\baselineskip}
}
Prerequisites:
Load kvoptions
Define the <family> for the options an a <prefix> that is used for the value storing macros, e.g.
\SetupKeyvalOptions{
family=MC,
prefix=my@
}
The names doesn’t matter but it is common to name the family in two or three upper case letters and to use an @ at the end of the prefix.
Steps to create a new command:
Declare the option <name> (type: string), e.g.
\DeclareStringOption{schoolname}
Process all options with \ProcessOptionsX
Use the values with \<prefix><name>, e.g.
{\centering\bfseries\sffamily
\my@schoolname
\par}
For more information about kvoptions see it’s documentation …