Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HTML code to laravel(or any framework)

My question is simple and may be very basic. What is the best way to convert HTML pages to Laravel.?

In HTML pages the links are like <a href="about-us.html">, we have to convert it to <a href="{{ URL::asset('about-us.html')}}"> for Laravel.

Now i am manually editing entire HTML code to achieve it. Is there any short way to do it.?(i used replace all in CodeIgniter) Or What is the best way to avoid this overwork? Any other workflow between designer and programmer?

Note: Please comment here if you dont understand this question well. I will edit it.:)

like image 599
jabir145 Avatar asked Sep 28 '13 06:09

jabir145


People also ask

Can I use HTML in Laravel?

Laravel provides various in built tags to handle HTML forms easily and securely. All the major elements of HTML are generated using Laravel. To support this, we need to add HTML package to Laravel using composer.

How can convert HTML image to Laravel?

use Spatie\Browsershot\Browsershot; Here's the easiest way to create an image of a webpage: Browsershot::url('https://example.com')->save($pathToImage); By default the screenshot's type will be a png.

Can I convert HTML to PHP?

The web server will know that everything between <? php and ?> is php code and will execute it, the rest will be sent directly to the browser, because it is just static HTML. So, you can “convert” every html page to php just by renaming the file with . php extension.


2 Answers

The easiest way is,

  1. Copy all HTML files, and paste them into the view folder.

  2. Change all files extensions from .html to .blade.php (eg. about.html to about.blade.php).

  3. Remove the '.html' from all anchors href, so <a href='about.html'> will be <a href='about'>. (Just replace .html with "" ).

  4. Copy all other files/folders (js folder, CSS folder, image folder, etc) from the root folder to the public folder.

  5. Create a route for your static pages. You can create a route for each page or you can create a single common route for all pages, like this.

     Route::get('{page_name}', function($page_name)
     {
         //
         return View::make('frontend/'.$page_name);
     });
    
  • It will take only 5 minutes to convert a complete 5-page static website.
like image 130
Fasil kk Avatar answered Oct 13 '22 23:10

Fasil kk


There is no way to do this without editing each and every page.

Laravel is based on Routing. So you can't convert your link to,

<a href="{{ URL::asset('about-us.html')}}">

Note the about-us.html. Instead of this you should do this,

First make a Route in app/routes.php

Route::get('about', function()
{
    return View::make('about');
});

Then save your about-us.html file as about.blade.php in app/views.

And you can make the link like this,

{{ HTML::link('about', 'About Us') }}

For better html conversion, see the HTMLBuilder API here.

like image 37
Anshad Vattapoyil Avatar answered Oct 13 '22 22:10

Anshad Vattapoyil