As much as some people would like you to believe that preview is the same as publish, its not. Some of the differences are technical (for example, published URLs follow your publication struture, whilst preview URLs resemble SmarEdit URLs) and some of the differences are practical (there is hardly any need to connect to Google Analytics from your preview - and if there is, you probably want to use a different account number anyway…)
Now, RedDot CMS provides block marks for choosing to output code in SmartEdit mode or not in SmartEdit mode - which basically means preview *and* publish. So, how do we output code in publish mode only? Well, we have two options (that I am aware of) - pre-execute code or Navigation Manager.
Using pre-execute code, we need to be able to test against something that exists in preview or publish - but not both. Thankfully, the session object fulfills this requirement nicely. Below, the inf_loginGuid placeholder is an info element that outputs the login guid of the current user’s session.
<!IoRangePreExecute><?php if ('<%inf_loginGuid%>' == '') { ?>
Publish only content
<?php } ?><!/IoRangePreExecute>
My preference is to functionalise this, put it somewhere accessible to all templates, and then call the function - but thats just me:
<!IoRangePreExecute><?php
function isPublish() { return ('<%inf_loginGuid%>' == ''); }
?><!/IoRangePreExecute>
<!IoRangePreExecute><?php if (isPublish()) { ?>
Publish only content
<?php } ?><!/IoRangePreExecute>
Navigation Manager has a specific tag - Context:CurrentRenderMode - which will output the mode: 0 = preview, 1 = SmartEdit and 2 = publish. You can use this within regular Navigation Manager If statements (not covered here), or similiar to the examples above, ie:
<!IoRangePreExecute><?php if ('<%!! Context:CurrentRenderMode !!%>' == '2') { ?>
Publish only content
<?php } ?><!/IoRangePreExecute>
<!IoRangePreExecute><?php
function isPublish() { return ('<%!! Context:CurrentRenderMode !!%>' == '2'); }
?><!/IoRangePreExecute>
So, what’s the catch? Well, you need Navigation Manager activated in order for the Navigation Manager solution to work - and I wouldn’t recommend that unless you are actually using Navigation Manager (for one, it requires a server config file change). But the placeholder method works fine. I leave it as an exercise for the reader to work out how to output code in preview only using the placeholder method 