RW8 and php rendering

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.

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.

echo realpath(dirname(__FILE__));

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); ?>
1 Like

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.

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.

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).


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

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.

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.

You might give a try with the new resource manager.

Will do. Thanks Doug.

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

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

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