LostKobrakai Posted September 1, 2014 Share Posted September 1, 2014 Hi, I've a function which outputs gallery markup. This gallery can be included in the text via a hanna code or should be placed below the other content. Somehow just setting a variable at the start of template rendering and use "global" to change it doesn't work. // _init.php $gallery_used = false; // _func.php function renderGallery(){ global $gallery_used; if(!$gallery_used) return "gallery"; else return "already used"; $gallery_used = true; } Link to comment Share on other sites More sharing options...
bernhard Posted September 1, 2014 Share Posted September 1, 2014 that may help: https://processwire.com/talk/topic/4717-global-not-working-in-templates/ 1 Link to comment Share on other sites More sharing options...
horst Posted September 1, 2014 Share Posted September 1, 2014 (edited) // _init.php $GLOBALS['gallery_used'] = false; // _func.php function renderGallery(){ if(!$GLOBALS['gallery_used']) { $GLOBALS['gallery_used'] = true; return "gallery"; } else { return "already used"; } } Edited September 1, 2014 by horst moved a line into the right direction :) 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 1, 2014 Author Share Posted September 1, 2014 // _init.php $GLOBALS['gallery_used'] = false; // _func.php function renderGallery(){ if(!$GLOBALS['gallery_used']) { $GLOBALS['gallery_used'] = true; return "gallery"; } else { return "already used"; } } With the exception of an error in the order your solution does work horst, thank you both. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now