# RW8 and php rendering

**URL:** <https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478>\
**Category:** RapidWeaver Classic\
**Created:** [August 14, 2018, 9:29pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478 "2018-08-14T21:29:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![1611mac](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/1611mac/32/5675_2.png) [@1611mac](https://forums.realmacsoftware.com/u/1611mac)\
**Post date:** [August 14, 2018, 9:29pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/1 "2018-08-14T21:29:10Z")

</div>

Can someone please provide more detail or point to docs for info with php rendering in RW8 and what it’s limitations are. I use php includes on my site and, of course, these includes have never rendered (I didn’t expect them to) but I’m unsure of what the “local” php rendering feature is all about in RW8. Bottom of RapidWeaver home page says:

> No fiddly MAMP setup required, add PHP into any page and it works just like magic!

Like previous versions, my includes don’t render in RW8. But then, the include code itself only resides on my server. Only the include “call” is in the project file.

---

<div class="post-metadata">

**Author:** ![isaiah](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/isaiah/32/93_2.png) [@isaiah](https://forums.realmacsoftware.com/u/isaiah)\
**Post date:** [August 14, 2018, 9:38pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/2 "2018-08-14T21:38:32Z")

</div>

a php include needs to include a relative file path or a complete file path.

the relative file path needs to start from the place it’s being called and then traverse to the place the file actually exists.

you can also use ` __DIR__ ` and ` __FILE__ ` to get the absolute path of the script that’s currently running.

try this in a php file and see what you get on the page, work from there. you should be able to get php to work almost the same as on the server.

```auto
echo realpath(dirname( __FILE__ ));

```

---

<div class="post-metadata">

**Author:** ![1611mac](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/1611mac/32/5675_2.png) [@1611mac](https://forums.realmacsoftware.com/u/1611mac)\
**Post date:** [August 14, 2018, 10:06pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/3 "2018-08-14T22:06:25Z")

</div>

humm… My calls now look like this which I believe provides a complete file path. These have been working for years live from server, but of course, never rendered in RW.

> \<?php $path = $\_SERVER['DOCUMENT\_ROOT']; $path .= "/includes/sidebar.html"; include\_once($path); ?\>

---

<div class="post-metadata">

**Author:** ![isaiah](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/isaiah/32/93_2.png) [@isaiah](https://forums.realmacsoftware.com/u/isaiah)\
**Post date:** [August 15, 2018, 12:08am UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/4 "2018-08-15T00:08:36Z")

</div>

That’s a fine way to go about it too. That will load a file that’s stored in /includes/sidebar.html – but you’ll need to make sure you have something there to include.

In preview-mode (and the new Simulation-mode) only a single page is exported along with resources and any extra files required by that one page (for instance Stacks often adds JS files, and image files, etc.).

I guess the next question is: where is this sidebar.html file coming from? Is that another RapidWeaver page? Or something that you upload to your server manually? Or maybe a folder of things you add to the RW project as a “resource”?

In each case there are probably some things you can do to make your Preview work a bit better by adjusting the path or having a locally exported copy of your `includes` folder.

---

<div class="post-metadata">

**Author:** ![1611mac](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/1611mac/32/5675_2.png) [@1611mac](https://forums.realmacsoftware.com/u/1611mac)\
**Post date:** [August 15, 2018, 12:51am UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/5 "2018-08-15T00:51:26Z")

</div>

Actually Isaiah, I’ve been successfully using that code for years. Back when I used Dreamweaver I learned how to do php includes. (Some I hand code, some I create in RW then I fix paths by hand and upload the appropriate snippet of code.)

But the php doesn’t render in RW8 preview either. Works fine live, always has. The actual includes (files) are manually uploaded to my server to an “includes” folder. Believe it or not, I’ve used RW 5, 6, 7 and now 8 and never used the RW “Resources.” Any “resources” I use I just upload manually and link to it.

I guess I don’t understand how RW renders php. Seems, I would have to have the includes available locally for RW to render them in preview but I would have no idea how to “replicate” the server path as a local path and then have both server and local includes work. So I question whether any kind of php code that contains a “path” would render in RW. Or am I totally missing something?

But if I remember correctly my includes worked fine in MAMP when I was using it… but that’s been some time ago… My memory may be unclear. But of course, with MAMP I had exported my RW pages to MAMP, and that included the includes.

---

<div class="post-metadata">

**Author:** ![instacks](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/instacks/32/23339_2.png) [@instacks](https://forums.realmacsoftware.com/u/instacks)\
**Post date:** [August 15, 2018, 5:53am UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/6 "2018-08-15T05:53:12Z")

</div>

> [@1611mac](#):
>
> my includes worked fine in MAMP

Yes, that’s the published version of the page.

At the end, you would have to make an if else block for:

if preview / else (publish)

To prefix your include with the correct path. AFAIK, the information if you are in preview or publish mode is only available for a plugin (or stack).

EDIT:

> [@1611mac](#):
>
> never used the RW “Resources

Of course with my above example, you would have to use the resources…

---

<div class="post-metadata">

**Author:** ![joeworkman](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/joeworkman/32/23780_2.png) [@joeworkman](https://forums.realmacsoftware.com/u/joeworkman)\
**Post date:** [August 15, 2018, 6:04am UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/7 "2018-08-15T06:04:20Z")

</div>

Getting PHP include of external files and libraries would be pretty tricky inside RapidWeaver. If you are doing something at that level, you may just be better off using MAMP.

---

<div class="post-metadata">

**Author:** ![1611mac](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/1611mac/32/5675_2.png) [@1611mac](https://forums.realmacsoftware.com/u/1611mac)\
**Post date:** [August 15, 2018, 12:10pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/8 "2018-08-15T12:10:34Z")

</div>

> [@instacks](#):
>
> At the end, you would have to make an if else block for:
> 
> if preview / else (publish)
> 
> To prefix your include with the correct path. AFAIK, the information if you are in preview or publish mode is only available for a plugin (or stack).

That’s helps Jannis, thanks! Perhaps I’ll play around with that concept. I understand your point. I would need to learn some things in order to grab the state. That would be a good project for me. Thanks.

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [August 15, 2018, 2:02pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/9 "2018-08-15T14:02:08Z")

</div>

You might give a try with the new resource manager.

---

<div class="post-metadata">

**Author:** ![1611mac](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/1611mac/32/5675_2.png) [@1611mac](https://forums.realmacsoftware.com/u/1611mac)\
**Post date:** [August 15, 2018, 2:05pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/10 "2018-08-15T14:05:18Z")

</div>

Will do. Thanks Doug.

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [August 15, 2018, 2:32pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/11 "2018-08-15T14:32:16Z")

</div>

Haven’t tried it yet, (it’s on my list) but it’s worth a try. Keep us posted.

---

<div class="post-metadata">

**Author:** ![instacks](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/instacks/32/23339_2.png) [@instacks](https://forums.realmacsoftware.com/u/instacks)\
**Post date:** [August 15, 2018, 3:06pm UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/12 "2018-08-15T15:06:36Z")

</div>

Using resources and the resources macro “should” make it work correctly.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/system/32/25301_2.png) [@system](https://forums.realmacsoftware.com/u/system)\
**Post date:** [September 15, 2018, 1:50am UTC](https://forums.realmacsoftware.com/t/rw8-and-php-rendering/21478/14 "2018-09-15T01:50:40Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
