A green and economical methodology to fabricate carbon-based materials with suitable pore size distributions is needed to achieve rapid electrolyte diffusion and improve the performance of supercapacitors. Here, a method combining in situ templates with self-activation and self-doping is proposed. By variation of the molar ratio of magnesium folate and potassium folate, the pore size distribution was effectively adjusted. The optimal carbon materials (Kx) have a high specific surface area (1021-1676 m2 g-1) and hierarchical pore structure, which significantly promotes its excellent capacitive properties. Notably, K2 shows an excellent mass specific capacitance of 233 F g-1 at 0.1 A g-1. It still retained 113 F g-1 at 55 A g-1. The assembled symmetric supercapacitor exhibited an outstanding cyclic stability. It maintains 100% capacitance after 100 000 cycles at 10 A g-1. The symmetric supercapacitor demonstrated a maximum power density of 99.8 kW kg-1. This study focuses on the preparation of layered pore structures to provide insights into the sustainable design of carbon materials.