Yard template is a space assignment at the tactical level, which is kept unchanged within a long period of time and significantly impacts the handling efficiency of a container terminal. This paper addresses a yard template planning problem considering uncertainty and traffic congestion. A two-stage stochastic programming model is formulated for minimizing the risk of containers with no available slots in the designated yard area and minimizing total transportation distances. The first-stage model is formulated for assigning vessels in each block without considering the physical location properties of blocks, and the second-stage model is formulated for designating physical locations to all blocks. Subsequently, a solving framework based on genetic algorithm is proposed for solving the first-stage model, and the CPLEX (a commercial solver) is used for solving the second-stage model. Finally, numerical experiments and scenario analysis are conducted to validate the effectiveness of the proposed model and the efficiency of the proposed solution approach.