Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can use in Wordpress? #32

Open
andreysuha2 opened this issue Jun 12, 2019 · 1 comment
Open

Can use in Wordpress? #32

andreysuha2 opened this issue Jun 12, 2019 · 1 comment

Comments

@andreysuha2
Copy link

Can i use this in wordpress? If yes, can you give me some examples how integrate to wordpress?

@gabrielpetry
Copy link

gabrielpetry commented Jul 29, 2019

Yes, we can. On my testing the easiest way was:

functions.php

<?php
    require_once __dir__ . "/vendor/autoload.php";
    use Jenssegers\Blade\Blade;

    function render(string $view, array $args = []) {
       $blade = new Blade(__dir__ . '/src/views', __dir__ . '/cache');
       echo $blade->make($view, $args);
    }

Then the default wordpress routes acts as controllers, so in home.php, for example:

<?php
    $posts = get_posts();

    render('home', array(
        'posts' => $posts
    ));

So the last step is to create a ./src/views/home.blade.php

<!DOCTYPE html>
<html lang="pt-br">
<head>
  <meta charset="UTF-8">
  {{-- {{ wp_head() }} --}}
  <title>{{ get_bloginfo('name') }} | {{ get_bloginfo('description') }}</title>
</head>
<body>
  
</body>
</html>

This is a WIP, any improvement ideas are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants