The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
|
Extend if/then with private pages - Printable Version +- GetSimple Support Forum (http://get-simple.info/forums) +-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3) +--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16) +--- Thread: Extend if/then with private pages (/showthread.php?tid=9988) |
Extend if/then with private pages - smsHH - 2017-09-19 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. RE: Extend if/then with private pages - Bigin - 2017-09-20 Hi smsHH, you could use nested function call to achieve this, something like: PHP Code: if(empty(returnPageContent('aktion', 'private'))) { 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) { You can then call this function as follows: PHP Code: echo getPublicPageContent('aktion'); ;-) RE: Extend if/then with private pages - shawn_a - 2017-09-20 use getPageField for private checking, it uses pagecache in bigin s first example instead of returnPageContent RE: Extend if/then with private pages - Bigin - 2017-09-20 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? RE: Extend if/then with private pages - smsHH - 2017-09-20 Thank you both, I will try that (and try to understand the code). :-) RE: Extend if/then with private pages - smsHH - 2017-09-20 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 --> Thank you :-) RE: Extend if/then with private pages - Bigin - 2017-09-20 Well, you could extend your getPublicPageContent() function before it returns the page content with the markup: PHP Code: ... RE: Extend if/then with private pages - smsHH - 2017-09-20 Simply amazing Thank you so much, Bigin! RE: Extend if/then with private pages - shawn_a - 2017-09-20 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 ? RE: Extend if/then with private pages - Bigin - 2017-09-20 Oh yes, that's right, the menu ... then $pagesArray has probably already been loaded |