Contain multiple page templates in one PHP custom template file in Wordpress?

As we know that WP has a feature called Page_Templates. But today, I got a question in my mind that can we add/use/access multiple page templates from single .php file (which is responsible to call page template.)

For example first 40 lines of demo-xyz.php will echo a demo page template and then after left lines echo a xyz template. then i want to select both as page template for different two pages in wordpresspagesaddnewpage attributesselect page template. (there both 1.demo 2.xyz template name should be shown)

example (file:demo-xyz.php)-

/*
Template : demo
*/

....Codes For template demo

/*
Template : xyz
*/

.... Codes for template xyz

Reason - I have multiple page templates and i am finding me unable to manage too much template files that's why i wanna it's solution.

I searched everywhere for it but not find out a solution anywhere

Topic get-template-part functions page-template php hooks Wordpress

Category Web


This is not possible, a PHP file can only contain a single page template. There is no way to combine the files.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.