Skip to content
Advertisement

Include HTML markup from another file inside PHP file

So this is the method that I am using and it’s kinda working, but I don’t think that it’s best practice and just seems kinda off, so I wanted to see if someone knew a much better and/or cleaner method on importing HTML markup that will be located in two locations.

So let’s say that I have my main index.php file:

JavaScript

Then I am calling <?php include_once 'pardot-form.php'?> in two locations because I don’t want to repeat the same HTML output twice, so the pardot-form.php file contains the following:

JavaScript

Is there a cleaner way to “Grab HTML markup and append it in two locations”, the only difference is the outer layer where one conditional is a container block and another is a modal.

I can even delete the pardot-form.php file and add in the HTML markup in the same index.php file if you know of a cleaner way.

All help is appreciated!

Advertisement

Answer

You could save include_once 'pardot-form.php' to a variable under the $mode = get_field('mode'); declaration and then use it wherever you want.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement