Check if in preview-mode in PHP

php

(Marc Vos) #1

Is there a way for PHP-code or HTML-code to see if a page is displayed in RW7-preview mode, live-preview mode or normal published-mode?

I need to set an explicit path to some PHP-includes in preview-mode.

Thanks,
Marc Vos


(Jannis from inStacks Software) #2

You would be able to do that with help of the Stacks Plugin API. That needs you to create a Stack, so might be a bit too much effort?


(Marc Vos) #3

It’s a piece of PHP code inside a HTML stack. It would be nice if I can use something like if(%%mode%% == ‘preview’) or so.

I can also duplicate the HTML-stack itself and make changes to it … but what change would I make to get what I want?

Thanks,
Marc


(Doobox Software) #4

@MrMacvos See here : http://api.yourhead.com/templates/display/


(Marc Vos) #5

Ok, thanks for the link. I’ll make a stack then and give it a try. I’m enabling the Rapidblog PHP code to display a Blogger feed in a stacks page, for use with Foundry. Rapidblog is a page-plugin and can’t be used with Foundry.

So making stacks out of it is a nice idea.

Marc


(Marc Vos) #6

I’m having a total misunderstanding of how to get content of a stack visible or published (cq. exported).
I have this:

%[if edit]%
Blogger posts stack
%[endif]%
%[if !edit]%
<?php
Lots of PHP code
?>
%[endif]%

in a ‘template.php’, with ‘preprocessor’ OFF.

I also tried with

%%[[if edit]]%%
Blogger posts stack
%%[[endif]]%%
%%[[if !edit]]%%
<?php
Lots of PHP code
?>
%%[[endif]]%%

with ‘preprocessor’ set to ON.

The plist for ‘templates’:

<dict>
	<key>filename</key>
	<string>template.php</string>
	<key>scope</key>
	<string>page</string>
	<key>type</key>
	<string>php</string>
</dict>

And I can’t get it to work.

I want it be a ‘control’ stack, like the Foundry-control stack. Use once on a page, and no stacks may be dragged into it.

What am I doing wrong?


(Marc Vos) #7

Ok, I got it, the API docs weren’t clear.
I changed the extension back to HTML, also in the plist.
That did at least generate content, but inside the HEAD section. Reason: I had the scope of the template-file set to ‘page’. I hoped that the content would be included in-place, but just once. Instead, it was placed in the head-section.
So I changed the scope back to ‘each’ and now it does want I want.

Previewing now also works.

Cheers,
Marc