Pixrael Posted April 25, 2017 Share Posted April 25, 2017 Hi, in my _main.php when I use the native PHP include() function, I can get in the include file, the vars declared in _init.php, but if I use the PW functions $files->include(), $files->render() or wireRenderFile() I don't have access to this vars. It's normal? I need to pass all this vars explicitly to the PW function? An example vars in _ini.php is $styles = $config->urls->templates.'styles'; ..I use the PW namespace in all my files.. Link to comment Share on other sites More sharing options...
Pixrael Posted April 25, 2017 Author Share Posted April 25, 2017 https://processwire.com/talk/topic/10350-passing-variables-using-wirerenderfile/ there are some answers to this questions, but I don't understand why native php include() can receive the variables Link to comment Share on other sites More sharing options...
louisstephens Posted April 25, 2017 Share Posted April 25, 2017 Have you looked at the template in the backend of processwire and checked to make sure that the checkbox for "Disable automatic prepend of file: _init.php" is unchecked? I believe by default processwire appends this file to all templates (unless you uncheck it) giving access to what is defined in init (someone please correct me if I am wrong). Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 25, 2017 Share Posted April 25, 2017 Only the native include() function does implicitly share variables with included php files. Any userland functions/methods cannot do that, which is why $files->include() cannot do it as well. $files->include() is there, because it's aware of processwire's filecompiler, if you don't need that you can simply use include() as well. 2 Link to comment Share on other sites More sharing options...
Pixrael Posted April 25, 2017 Author Share Posted April 25, 2017 louisstephens the prepend file option is ok, thanks. @lostkobrakai - thanks for clarifying that. Another question for you: what is best (in your opinion of course) for stuff like twitter cards, facebook cards, prefetch tags, etc.. use an include file with the logic + markup, or use a function that do the logic and return the same markup? Link to comment Share on other sites More sharing options...
abdus Posted April 25, 2017 Share Posted April 25, 2017 3 hours ago, Pixrael said: what is best (in your opinion of course) for stuff like twitter cards, facebook cards, prefetch tags I use a partial template for those. I have a meta-social.php where I keep FB, Twitter specific meta tags, and call it (and optionally pass specific variables) with wireRenderFile('partial/meta-social', ['a' => 1, 'b' => 2]); inside template files. Same for JSON+LD data for microdata. region('foot+', partial('meta-breadcrumbs')); region('foot+', partial('meta-site')); region('foot+', partial('meta-analytics')); region('+head', '<link rel="dns-prefetch" href="//www.google-analytics.com">'); For prefetch tags, like CSS, and JS that needs to be in every page, I use _init.php that is prepended to every template (using $config->prependTemplateFile), but template specific assets goes to individual template files. If you're using delayed output strategy, I recomment region() function that comes with Functions API (enable $config->useFunctionsAPI = true) where you can define regions and append prepend any string. https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api Link to comment Share on other sites More sharing options...
Pixrael Posted April 25, 2017 Author Share Posted April 25, 2017 3 hours ago, abdus said: I use a partial template for those. I have a meta-social.php where I keep FB, Twitter specific meta tags, and call it (and optionally pass specific variables) with wireRenderFile('partial/meta-social', ['a' => 1, 'b' => 2]); inside template files. Same for JSON+LD data for microdata. region('foot+', partial('meta-breadcrumbs')); region('foot+', partial('meta-site')); region('foot+', partial('meta-analytics')); region('+head', '<link rel="dns-prefetch" href="//www.google-analytics.com">'); For prefetch tags, like CSS, and JS that needs to be in every page, I use _init.php that is prepended to every template (using $config->prependTemplateFile), but template specific assets goes to individual template files. If you're using delayed output strategy, I recomment region() function that comes with Functions API (enable $config->useFunctionsAPI = true) where you can define regions and append prepend any string. https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api I already use a configuration similar to you, where the modern favicon, social tags, json schemas, prefetch, etc. is under each own partial, and in _main.php I include the partials common for all pages, and the templates files put the rest, but instead of region() function I use the new <region> tags because allow me to use all the autocomplete features of my IDE. ..inside the partials sometimes I need to do adjustments before echo and the related queries are made there. A question: partial() is a function from your arsenal to include files eh? My question to @LostKobrakai is because in some post before, he talk about using a call to a function to render the same partials in the head, something similar to the renderNav() function from the PW starter profiles.. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 26, 2017 Share Posted April 26, 2017 I've used all sorts of different styles in my projects, so really it depends on how flexible your markup does need to be and how you want to pass data to your partials. 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