<p>Your app can load up Craft using its bootstrap.php file:</p>



<pre class="lang-php prettyprint-override"><code>$craft = require 'path/to/craft/app/bootstrap.php';
</code></pre>

<p>That file returns a <a href="http://buildwithcraft.com/classreference/etc/web/WebApp" rel="nofollow">Craft\WebApp</a> instance. From it, you can access all of Craft’s services, including the <a href="http://buildwithcraft.com/classreference/services/ElementsService" rel="nofollow">ElementsService</a> which provides APIs for fetching elements and their content.</p>

<p>Read through our <a href="http://buildwithcraft.com/docs/plugins/working-with-elements" rel="nofollow">Working with Elements</a> guide to get an idea of how those APIs work.</p>

<p>As a quick example, here’s how you’d get the entries in a section with an ID of <code>1</code> with a category selected, with an ID of <code>5</code>:</p>

<pre class="lang-php prettyprint-override"><code>$criteria = $craft-&gt;elements-&gt;getCriteria(Craft\ElementType::Entry);
$criteria-&gt;sectionId = 1;
$criteria-&gt;relatedTo = array('targetElement' =&gt; 5);

$entries = $criteria-&gt;find();
</code></pre>

<p>To get the HTML for an entry, you could either assemble that in PHP based on the entry’s content fields, but it would probably be easier to just write a <a href="http://buildwithcraft.com/docs/templating-overview" rel="nofollow">template</a> for it, and have <a href="http://buildwithcraft.com/classreference/services/TemplatesService#render-detail" rel="nofollow">TemplatesService::render()</a> render it for you:</p>

<pre class="lang-php prettyprint-override"><code>$html = $craft-&gt;templates-&gt;render('path/to/templates', array(
    'entries' =&gt; $entries
));
</code></pre>

CC BY-SA 3.0
2014-11-06T15:32:31.847Z
2014-11-06T15:32:31.847Z
Brandon Kelly
<p>We have a CakePHP 2.5 app for which we'll very soon be building a learning centre/knowledge base. Craft is one of the tools we're considering for that due to its apparent suitability for content editors to create longform, mixed content consisting of text, images and videos without ending up with junk HTML.</p>

<p>For a couple of reasons, it might be preferable for us to have the learning centre content served as part of the app rather than via Craft at a subdomain, so we'd like to know how we would pull in just the generated HTML Content for the actual article content from Craft for embedding within the app's layout.</p>

<p>The learning centre will have four categories, each with an unknown number of articles.</p>

<p>We'd need to be able to reference each article, and maybe each category, from within the app as users can be set parts of the learning centre as tasks.</p>

<content>
How can Craft-generated Content HTML be accessed via an external PHP app?
# How can Craft-generated Content HTML be accessed via an external PHP app?

(Asked by: username_0 on 2014-11-06)

We have a CakePHP 2.5 app for which we'll very soon be building a learning centre/knowledge base. Craft is one of the tools we're considering for that due to its apparent suitability for content editors to create longform, mixed content consisting of text, images and videos without ending up with junk HTML.

For a couple of reasons, it might be preferable for us to have the learning centre content served as part of the app rather than via Craft at a subdomain, so we'd like to know how we would pull in just the generated HTML Content for the actual article content from Craft for embedding within the app's layout.

The learning centre will have four categories, each with an unknown number of articles.

We'd need to be able to reference each article, and maybe each category, from within the app as users can be set parts of the learning centre as tasks.

**Tags:** content

---

## 1 answers

### Answer by username_1 on 2014-11-06. Score: 4 | Accepted answer

Your app can load up Craft using its bootstrap.php file:
$craft = require 'path/to/craft/app/bootstrap.php';

That file returns a Craft\WebApp instance. From it, you can access all of Craft’s services, including the ElementsService which provides APIs for fetching elements and their content.
Read through our Working with Elements guide to get an idea of how those APIs work.
As a quick example, here’s how you’d get the entries in a section with an ID of 1 with a category selected, with an ID of 5:
$criteria = $craft->elements->getCriteria(Craft\ElementType::Entry);
$criteria->sectionId = 1;
$criteria->relatedTo = array('targetElement' => 5);

$entries = $criteria->find();

To get the HTML for an entry, you could either assemble that in PHP based on the entry’s content fields, but it would probably be easier to just write a template for it, and have TemplatesService::render() render it for you:
$html = $craft->templates->render('path/to/templates', array(
    'entries' => $entries
));


---

