  In this work, we calculate the $CP$-averaged branching ratios and direct
$CP$-violating asymmetries of the quasi-two-body decays $B_{(s)}\to P
f_2(1270)\to P\pi\pi$ with the two-pion distribution amplitude
$\Phi_{\pi\pi}^{\rm D}$ by using the perturbative QCD factorization approach,
where $P$ represents a light pseudoscalar meson $K, \pi, \eta$ and
$\eta^{\prime}$. The relativistic Breit-Wigner formula for the $D$-wave
resonance $f_2(1270)$ is adopted to parameterize the timelike form factor
$F_{\pi}$, which contains the final state interactions between the pions in the
resonant regions. The consistency of theoretical results with data can be
achieved by determining the Gegenbauer moments of the $D$-wave two-pion
distribution amplitudes. The decay rates for the considered decay modes are
generally in the order of $10^{-9}$ to $ 10^{-6}$. The integrated direct $CP$
asymmetries for the charged modes agree with the {\it BABAR} and Belle
measurements. As a by-product, we extract the branching ratios of $B_{(s)}\to
Pf_2(1270)$ from the corresponding quasi-two-body decay modes, which still need
experimental tests at the ongoing and forthcoming experiments.
