Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

[Beginner] Splitting my index.html into two parts

lmnu

Coder
Hello,

I want to split my html code into two files (index.html and contact.html). At the moment I have in my index.html this :

HTML:
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/owl.carousel.min.css">
    <link rel="stylesheet" href="css/owl.theme.default.min.css">
    <link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
    <link rel="stylesheet" href="css/style.css">
 
    <title>Coucou</title>
</head>
 <body>
    <!-- BOTTOM NAV -->
    <nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
        <div class="container col-auto">
            <div class="collapse navbar-collapse" id="navbarNav" class="row justify-content-center">
                <a href="#" data-bs-toggle="modal" data-bs-target="#ContactModal" class="btn btn-brand ms-lg-3">Contact</a>
            </div>
        </div>
    </nav>
 
            <!-- Modal -->
            <div class="modal fade" id="ContactModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-xl">
                    <div class="modal-content">
                        <div class="modal-body p-0">
                            <div class="container-fluid">
                                <div class="row gy-4">
                                    <div class="col-lg-8">
                                        <form class="p-lg-5 col-12 row g-3">
                                            <div class="col-lg-6">
                                                <label for="userName" class="form-label">First name</label>
                                                <input type="text" class="form-control" placeholder="Jon" id="userName"
                                                    aria-describedby="emailHelp">
                                            </div>
                                            <div class="col-12">
                                                <button type="submit" class="btn btn-brand">Send Message</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
        
                    </div>
                </div>
            </div>
 
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.bundle.min.js"></script>
    <script src="js/owl.carousel.min.js"></script>
    <script src="js/app.js"></script>
</body>
 
</html>

I would like to put the part (ModalContact) in a contact.html file !!!
After several searches I can't find the solution

Thanks for your help
 
I think a simpler way is to use PHP (no PHP knowledge required)
  1. Rename your index.html to index.php.
  2. Put your contact markup in a file named contact.php.
  3. In your index.php use the PHP include or require statements to get the contents of the contact.php
  4. If using include, use this code: <?php include "contact.php"; ?>
  5. If using require, just replace include with require: <?php require "contact.php"; ?>

More about include and require here: https://www.w3schools.com/PHP/php_includes.asp

Unfortunately this will only work if you're using it on a server.
 
There also seems to be a much shorter solution with jQuery (the SO link I posted). But as I don't use jQuery I did not try that out.
Still I find it strange that HTML does not have a simple include syntax. Perhaps there's a good reason for that ?
 
Back
Top Bottom