Leaderboard
Popular Content
Showing content with the highest reputation on 09/29/2019 in all areas
-
4 points
-
@Noel Boss I'm using this code in hooks to Templatefile::render and didn't have any issues with it. if (strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0 || $this->wire('page')->template->name == 'admin') return;2 points
-
Doesn't this work? if ($this->page->template == 'admin') { echo "in admin"; } else { echo "not in admin"; } It surely works in ready.php. (Maybe you'd have to alter the syntax a bit... wire instead of this) Just tried this inside one of my modules, and it works as expected: public function init() { parent::init(); if ($this->page->template == 'admin') { $this->wire->message("in admin"); } else { $this->wire->message("not in admin"); } }2 points
-
Please don't use this module any more. I think in the end it just adds more complexity (and dependencies) than benefits. See this tutorial how simple it is to create a custom runtime-only Inputfield: WHY? I've started building this module because the existing solutions by @kongondo and @kixe (https://modules.processwire.com/modules/fieldtype-runtime-markup/ and https://github.com/kixe/FieldtypeMarkup) did not exactly fit my needs. Actually this module is aimed to be a base module that can easily be extended by other modules. It takes care of the heavy lifting that has to be done when working with custom fieldtypes in ProcessWire (injecting scripts and styles, handling JS events, doing translations). See RockTabulator as an example. I'm quite sure more will follow (eg ChartJS)... WHAT? This module helps you injecting ANY php/html/js/css into any PW backend form (either on a page or in custom process modules). It also comes with a sandbox process module that helps you setup your fields and provides handy shortcuts that integrate with TracyDebugger and your IDE: WHERE ...to get it? At the moment the module is released as early alpha and available only on github: https://github.com/BernhardBaumrock/RockMarkup2 If you have any questions or ideas please let me know ? PS: This module shows how easy it is to extend this module for your very own needs. All you need to do is providing the module's info arrays and then overwrite any methods that you have to modify (eg the InputField's render() method): https://github.com/BernhardBaumrock/RockMarkupExtensionExample1 point
-
? PW Pros… I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am? Right now, I use the following method inside one of my modules: public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?1 point
-
I like it! Not only is it easier but it makes it less likely that the setting of the $wire variable will be accidentally left behind after debugging is finished.1 point
-
$page->parents() can take a selector: foreach($page->parents('template!=myTemplate') as $item) { // ...1 point
-
article: The perils of functional CSS (sometimes referred to as atomic CSS) https://www.browserlondon.com/blog/2019/06/10/functional-css-perils/ Quote: "...if you don’t have a dedicated front-end team to handle this end of things, I can see how functional CSS would be useful. I don’t think it’s a coincidence that back-end developers have written most functional CSS libraries."1 point
-
Hello - Thanks for your great module! I have a special need for the side, I'm working on right now: Is there a possibility not to show the "result_summary_field" in the rendered results, but the 'near' content of the search-match in the search field itself - with the match highlited? So lets say there is this content in the search_index field: ' Hey - this is just a simple little test for the search engine!' I am searching for the phrase 'little'. The rendered result now should show me lets say: '... just a simple little test for the s...' To be honest: My php-skills are not that good to understand all the files of your module - but as far as I can see, I am afraid that it will not be possible in an easy way to change the code for my needs!? Thanks for any reply!1 point
-
Actually I'm still working on minor details, but I'll have it posted by 5pm EST.1 point
-
Just added support to hide columns in the final output. Before I've always hidden those columns via JavaScript in the final table, but if you don't need them, why not removing them from the result before transmitting them to the client? Now it is as simple as that - and the example also shows the new concept for single-page-reference joins which I really enjoy using as it is so much clearer than in RockFinder1: $rf = new RockFinder2(); $rf->find('template=husband'); $rf->addColumns(['title', 'wife']); // wife is a single page reference // find all wifes $wives = new RockFinder2(); $wives->find("template=wife"); $wives->addColumns(['title']); $rf->addJoin($wives, 'wife'); Result so far: id | title | wife | wife:title --------------------------------- 11 | John | 22 | Sue Hide the wife column (the page id of wife pagefield): $rf->hideColumns(['wife']); id | title | wife:title -------------------------- 11 | John | Sue ?1 point
-
Be careful here @Autofahrn and @psy. @VeiJari is talking about init.php and not _init.php. init.php ready.php finished.php Just to keep this in mind. https://processwire.com/blog/posts/processwire-2.6.7-core-updates-and-more/1 point
-
It depend on your needs, check : [...] const statusInit = 2; // system and modules are initializing const statusReady = 4; // system and $page are ready [...] E.g: in init.php, $page is not accessible (called too early) in ready.php, $page is accessible. Summarily said, new API variables are set (populated) before your prepended file to be consumed in your templates. If you want to access the $general variable as is from a template, you will have to set it in ready.php because here you can know the template/page context. Check those four examples.. Let's say we want to debug $general from our home.php template using Tracy with bd($general); #1 - Set new API var in init.php : (both call return null because we try to access the API var from a template, but still here the template context is unknown) $general is null $wire->general is null #2 - Set the new API var in ready.php : $general is populated $wire->general is populated #3 - Set the new API var in _init.php : $general is null $wire->general is populated #4 - Set the new API var in home.php : (same result as _init.php) $general is null $wire->general is populated Hopefully this will make thing clearer for you though an expert could explain deeper the thing.1 point
-
What @BitPoet said. In other words, PHP is fast, MySQL is fast. So, there is no guarantee that you will have only 1 page created per second (your date), or even per microsecond! That leaves you with uniqueness dependent only on the customer ID ($client->CustomerCode). If you can guarantee that customer IDs are unique and that they only appear once per data set, (your JSON array) then you would be fine. The fact that you are getting a SQL error tells us that either your customer IDs are not unique and/or one customer ID is appearing more than once in your data set (i.e., it may be uniqe to the customer, but not the data set). If the database says so, then it must be so . Let me illustrate (non-unique customer ID and/or replicated customer ID): $clientCustomerCode = 12345;// replicating repeated use of customer ID $p = $pages->get(1722); for ($i=0; $i < 30; $i++) { // Create new page $new = new Page(); // Create unique hash {no guarantee this will be unique if same customer ID used} $unique = md5(date("Y-m-d H:i:s") . "-" . $clientCustomerCode); // even these (microseconds) do not guarantee uniqueness throughout #$unique = round(microtime(true) * 1000) . "-". $clientCustomerCode; #$unique = microtime(true) . "-". $clientCustomerCode; #$unique = microtime() . "-". $clientCustomerCode; echo $i . ': ' . $unique . '<br>';// display 'uniqueness'; you should see duplicates here // Set some variables for the new page //$new->setOutputFormatting(false);// not needed for a new page (I think) $new->template = "basic-page"; $new->parent = $p; // Create hash $new->title = "Title " . rand(5,15);// just for testing $new->name = $unique;// not really unique! // Save the page #$new->save();// you'll get PDO error here within a second } Using the above code, you'll be hit by the duplicate entry violation error within a second...1 point
-
This is because of variable scope in PHP. Every function has its own internal scope. So this doesn't work: $vegetable = "Beetroot"; function vegetableOpinion() { // $vegetable is undefined in this function's scope return "$vegetable is delicious!"; } echo vegetableOpinion(); But you can pass in $vegetable as an argument to the function so it is available within the function's scope: function vegetableOpinion($vegetable) { return "$vegetable is delicious!"; } // Could be defined in _init.php if you like $vegetable = "Beetroot"; // Pass in $vegetable as an argument to the function echo vegetableOpinion($vegetable);1 point
-
I don't share the warm fuzzy feelings I get when I use people's modules nearly often enough, so I just left a comment on the module directory page. The short version is that it's saving me from having to create custom modules for a lot of places where I'd want to output some custom, processed output when editing a page and it is streamlining some of the steps I need to perform when approving entries in the dev directory, so thanks for this!1 point
-
$page=new Page(); $page->template='basic-page'; $page->parent='/mommy/'; $page->name=microtime(); // .or $page->name='gilderbergersbang' . $page->parent->numChildren;1 point