Additional to the cabin fare, you have to pay the normal fare for the ticket. Example Marrakesh to Tanger: EUR 20 + cabin type.
Buy the train ticket at a railway station. Note: in some countries you have to pay a service fee at the ticket counter. The ticket can be purchased at a station in the country of departure, also sometimes in other countries.