<p>You should take a look into Craft's <code>index.php</code> file. It sets some constants, autoloads Composer dependencies and loads the environment file before actually loading the script that you tried. Here is the snippet:</p>
<pre><code>&lt;?php
/**
 * Craft web bootstrap file
 */

// Set path constants
define('CRAFT_BASE_PATH', dirname(__DIR__));
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';

// Load dotenv?
if (class_exists('Dotenv\Dotenv') &amp;&amp; file_exists(CRAFT_BASE_PATH.'/.env')) {
    Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();
}

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
$app-&gt;run();
</code></pre>

CC BY-SA 4.0
2021-04-21T22:54:00.403Z
Thanks, that did it. :)
Tyssen
CC BY-SA 4.0
2021-04-21T08:36:00.530Z
2021-04-21T08:36:00.530Z
Johannes
<p>I'm working on a site that is running Craft v2 and also has an installation of Simple Machines Forum (SMF). This has been fine using the approach outlined in <a href="https://craftcms.stackexchange.com/a/23665/35">this answer</a>, i.e.</p>
<pre><code>$craft = include '/craft/app/bootstrap.php';
echo $craft-&gt;templates-&gt;render('includes/nav');
</code></pre>
<p>Now the site is being upgraded to v3 and this isn't working anymore. I've tried this:</p>
<pre><code>$craft = include '/craft/vendor/craftcms/cms/bootstrap/web.php';
echo Craft::$app-&gt;getView()-&gt;renderTemplate('includes/nav');
</code></pre>
<p>but with that I get:</p>
<blockquote>
<p>Uncaught Error: Class 'craft\services\Config' not found in /craft/vendor/craftcms/cms/bootstrap/bootstrap.php on line 165</p>
</blockquote>
<p>What else is missing to get this to work for Craft 3?</p>

<templating>
Displaying Craft templates in external apps
# Displaying Craft templates in external apps

(Asked by: username_0 on 2021-04-21)

I'm working on a site that is running Craft v2 and also has an installation of Simple Machines Forum (SMF). This has been fine using the approach outlined in this answer, i.e.
$craft = include '/craft/app/bootstrap.php';
echo $craft->templates->render('includes/nav');

Now the site is being upgraded to v3 and this isn't working anymore. I've tried this:
$craft = include '/craft/vendor/craftcms/cms/bootstrap/web.php';
echo Craft::$app->getView()->renderTemplate('includes/nav');

but with that I get:

Uncaught Error: Class 'craft\services\Config' not found in /craft/vendor/craftcms/cms/bootstrap/bootstrap.php on line 165

What else is missing to get this to work for Craft 3?

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2021-04-21. Score: 2 | Accepted answer

You should take a look into Craft's index.php file. It sets some constants, autoloads Composer dependencies and loads the environment file before actually loading the script that you tried. Here is the snippet:
load();
}

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
$app->run();

> **Comments:**
> **username_0**: Thanks, that did it. :)  

---

