-2

I have built a website using html, css and php. I have downloaded and installed drupal 8 to use a CMS system to take the sites design to the next level. I have ordered one book and been searching online and unable to find anything that explains what I want to do. If I have the below simplified example code now, how do I make the page use the Drupal 8 theme I have?

File welcome.php

<html>
<head>
<title>Welcome Page</title>   
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<?php
include_once "navBar.php";
echo '<div id="content">';
echo "Welcome to the site";
?>
</div>
</body>
</html>
  • Wouldn't make much sense to have a CMS when you then let it render legacy PHP. Please follow this linked guide on how to create a custom page programmatically. But I think you actually should read into the book you bought and find out everything they have about content types, how to create your own content type, what a node is and what the difference between page-, node- and field-templates is. Good luck! 🍀💙 – leymannx Feb 13 at 17:04
  • Thanks for helping leymannx. I have read about content types but my site is hundred of pages long and I was hoping not to have to recreate everything. That's why I was hoping it would be a call out like calling out a css file. Is it easier to to just redo everything or do custom pages? – Mafia Omerta Feb 13 at 17:16
  • Create the Drupal page with dummy content like you want to have it and then find a way to programmatically migrate your old project into nodes. – leymannx Feb 13 at 17:24
  • You're likely going to need to know how to build your website the "Drupal way." For example, your navbar.php should probably become a Drupal "menu" structure. What are you trying to accomplish by moving the site to Drupal? – codesmith Feb 13 at 17:51
  • 1
    It might be worth your while to learn how to do "site building" in Drupal. You can do a lot without needing to get into front end programming. Maybe try building your site in Drupal with an off the shelf theme and getting a basic page going with the header, nav, footer, and content presenting the way you like it. Then you'd likely need to look at the Migrate module for moving your custom MySQL content into Drupal. – codesmith Feb 13 at 19:43
0

You can add a new controller by defining the route for the welcome page in your module's routing.yml and markup the php content in that controller method. When you will hit the page url the content will be visible to you. You can also add the welcome.php to your base directory where you can access the url yoursite.com/welcome.php no matter which theme is enabled, the url will be accessible.

moduleName.routing.yml:

sample.path:
  path: '/welcome'
  defaults:
    _controller: \Drupal\partner\Controller\PartnerController::welcomeInfo
  requirements:
    _permission: 'access content'
  options:
     no_cache: 'TRUE'

src/Controller/controller.php:

class Controller extends ControllerBase{
  public function welcomInfo(){
    $customCode="<div>Welcome</div>";
    return [
      "#markup"=>$customCode
    ];
  }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.