GetSimple Support Forum

Full Version: Extend if/then with private pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everybody,

I would like to extend my if/then statement with an argument whether the page is set to private or not. Its content shouldn't be shown if its private.

How should I add that part to this existing code?

PHP Code:
if (!empty(returnPageContent('aktion'))) { ?>

Thank you very much in advance.
Hi smsHH,

you could use nested function call to achieve this, something like:

PHP Code:
if(empty(returnPageContent('aktion''private'))) {
    if(!empty(
returnPageContent('aktion'))) {
        ...
    }


However, it is not optimal, because the file has to be read 2 times. A better option would be to write a simple custom function for this purpose:

PHP Code:
function getPublicPageContent($slug) {
    
$data getXml(GSDATAPAGESPATH.$slug.'.xml');
    if(isset(
$data) && empty($data->private)) {
        return 
exec_filter('content'stripslashes(htmlspecialchars_decode($data->contentENT_QUOTES)));
    }


You can then call this function as follows:

PHP Code:
echo getPublicPageContent('aktion'); 

;-)
use getPageField for private checking, it uses pagecache in bigin s first example instead of returnPageContent
Yes, you could also use getPageField. But I think, in this case, it makes not really sense to use page cache, if only one page needs to be checked. Page cache makes sense only if $pagesArray already in memory and several pages should to be checked within a loop, for example. Or did I misunderstood something there?
Thank you both, I will try that (and try to understand the code). :-)
Great, it works. Thank you again!

A small question though. I need to wrap the content into some HTML. How can I achieve that the markup will be shown only if the page isn't set to private (or/and has content), too?

PHP Code:
<!-- Start Aktion -->
<
div id="aktion">
<?
php echo getPublicPageContent('aktion'); ?>
  <div class="closeaktion" title="Fenster schlie&szlig;en">&times;</div>
</div>
<!-- Ende Aktion --> 

Thank you :-)
Well, you could extend your getPublicPageContent() function before it returns the page content with the markup:

PHP Code:
...
if(isset(
$data) && empty($data->private)) {
    
$content =
        
'<div id="aktion">'.
            
exec_filter('content'stripslashes(htmlspecialchars_decode($data->contentENT_QUOTES))).
            
'<div class="closeaktion" title="Fenster schließen">&times;</div>'.
        
'</div>';
    return 
$content;

Simply amazing Exclamation

Thank you so much, Bigin!
for future reference yeah only use page cache when you need it, if you need info on more than one page etc, but as of 3.3.x I think its always loaded, its not lazy until 3.4, where do you think the menu comes from ?
Oh yes, that's right, the menu ... then $pagesArray has probably already been loaded