Git Product home page Git Product logo

Comments (8)

dmgawel avatar dmgawel commented on June 11, 2024 19

I just made an attempt (successful for now) to move required files to root directory. I'd like to share steps to reproduce this modified setup and issues I've come across. Maybe this will help with development.

Sage setup with required theme files in top-level directory

  1. Move index.php, functions.php, style.css and screenshot.png to theme's root directory.

  2. Move resources/views to root (/views). This is required for Page Templates to work because WordPress is looking for them only one level deeper than style.css is located.

Then, tell Sage where to look for view files. In config/views.php:

     'paths' => [
-        get_theme_file_path().'/resources/views',
-        get_parent_theme_file_path().'/resources/views',
+        get_theme_file_path().'/views',
+        get_parent_theme_file_path().'/views',
     ],

Additionally, until roots/sage#1980 is merged, fix template hierarchy in app/helpers.php:

function filter_templates($templates)
                     return [
                         "{$path}/{$template}.blade.php",
                         "{$path}/{$template}.php",
-                        "{$template}.blade.php",
-                        "{$template}.php",
                     ];
-                });
+                })
+                ->concat([
+                    "{$template}.blade.php",
+                    "{$template}.php",
+                ]);
         })
         ->filter()
         ->unique()
  1. In functions.php fix paths to loaded files:

Composer autoloader:

/**
  * Ensure dependencies are loaded
  */
 if (!class_exists('Roots\\Sage\\Container')) {
-    if (!file_exists($composer = __DIR__.'/../vendor/autoload.php')) {
+    if (!file_exists($composer = __DIR__.'/vendor/autoload.php')) {
         $sage_error(
             __('You must run <code>composer install</code> from the Sage directory.', 'sage'),
             __('Autoloader not found.', 'sage')

Sage required files:

/**
  * Add or remove files to the array as needed. Supports child theme overrides.
  */
 array_map(function ($file) use ($sage_error) {
-    $file = "../app/{$file}.php";
+    $file = "./app/{$file}.php";
     if (!locate_template($file, true, true)) {
         $sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
     }

Disable filter correcting paths to theme in default Sage setup:

-array_map(
-    'add_filter',
-    ['theme_file_path', 'theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'],
-    array_fill(0, 4, 'dirname')
-);

Paths to config files:

 Container::getInstance()
     ->bindIf('config', function () {
         return new Config([
-            'assets' => require dirname(__DIR__).'/config/assets.php',
-            'theme' => require dirname(__DIR__).'/config/theme.php',
-            'view' => require dirname(__DIR__).'/config/view.php',
+            'assets' => require __DIR__.'/config/assets.php',
+            'theme' => require __DIR__.'/config/theme.php',
+            'view' => require __DIR__.'/config/view.php',
         ]);
     }, true);
  1. Fix paths to controllers and models (if used).

Default directory in soberwp/controller and soberwp/models assume that required files are in resources directory. This might change in future (soberwp/controller#54) but for now in app/setup.php add:

/**
 * Soberwp Models
 */
add_filter('sober/models/path', function () {
    return get_theme_file_path() . '/app/models';
});

/**
 * Soberwp Controller
 */
add_filter('sober/controller/path', function () {
    return get_theme_file_path() . '/app/controllers';
});

That's it. Everything should be working now as expected. Hope this helps :-)

from sage-installer.

jkwasniak avatar jkwasniak commented on June 11, 2024 11

It would be great if a task to package theme (of using the WordPress installer) with all required dependencies is added so it can be directly invoked using yarn run (example: yarn run build:wordpress-installer-production).

from sage-installer.

josialoos avatar josialoos commented on June 11, 2024 2

Everyone who is interested in uploading roots-built sage theme to a normal wp-install on shared hosting ftp server setups should have a look at this script by @knowler. It's super neat tool for this. as easy as using one yarn command, uploading via ftp and activating the theme. voila.
https://github.com/knowler/sage-prep

from sage-installer.

MikeiLL avatar MikeiLL commented on June 11, 2024 1

Found it.

Update config/views.php.

'paths' => [
    get_theme_file_path().'/resources/views',
    get_parent_theme_file_path().'/resources/views',
],

Remove /resources from the paths.

from sage-installer.

MikeiLL avatar MikeiLL commented on June 11, 2024

@dmgawel Does this fix work at this point? From your EDIT note above I am gathering not.

from sage-installer.

dmgawel avatar dmgawel commented on June 11, 2024

@MikeiLL I've just updated my previous post. It now contains working solution :-)

from sage-installer.

MikeiLL avatar MikeiLL commented on June 11, 2024

Hey thanks @dmgawel I'm almost there.

However, illuminate/view/FileViewFinder.php is looking for blades in

partials.page-headerArray
(
    [0] => /var/www/html/wp-content/themes/MyTheme/resources/views
    [1] => /var/www/html/wp-content/themes/MyTheme/resources/views
)

If I copy the views directory back there the theme loads, but that's obviously not the answer.

Is there config somewhere I missed? Asking at Roots Discourse as well. Thanks.

from sage-installer.

dmgawel avatar dmgawel commented on June 11, 2024

@MikeiLL thanks! Indeed, I have this change also in my code but forgot to include it. I'm going to edit my post and add it for future reference.

from sage-installer.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.