Jump to content

kongondo

PW-Moderators
  • Posts

    7,529
  • Joined

  • Last visited

  • Days Won

    160

Everything posted by kongondo

  1. What tool is that, btw?
  2. Hi @derelektrischemoench, This code: $targetPage = $pages->get($menuItem->id); is the problem. For objects returned by getMenuItems(), id refers to the internal menu item ID in the collection AND NOT the corresponding ProcessWire page ID :-). Apologies, documentation could be clearer. To get the ProcessWire page ID of that menu item, use pagesID instead. So: $targetPage = $pages->get($menuItem->pagesID); By the way, please note that menu items with a pagesID of 0 are external menu items (e.g. an item pointing to google.com, etc). And while we are here.. This: $targetPage->get('images'); Could be changed to: $targetPage->images; However, your code shows that you are returning the whole 'images' field object. That is why you see this: ["pictures"]=> object(ProcessWire\Pageimages)#235 (2) { ["count"]=> int(1) ["items"]=> array(1) { ["steinlampe_2_grayscale.png"]=> string(26) "steinlampe_2_grayscale.png" Is that intentional? Aren't you really after the url of the image? Secondly, how many images are in each menu item's images field? Is the image field a multi image field or single? If multi, you need to loop through it if you want multiple images from it, or get the first one using first(). If it is a single image field, you are fine, you can just grab the URL.
  3. Or remove them. You don't need them in this case ?
  4. Haven't looked at the inner workings of this yet, but is this something (caching) that Wire Cache could do?
  5. I have updated the original snippet (variables API) in the Gist. This addresses the > issue reported by @adrian. Typing doesn't change. E.g.g pagesfind vs pages find will return the same suggestion.
  6. Facepalm! ?. I was testing in a workspace where wire folder was not part of the workspace!!! Thanks guys. It works. After further testing, I think I'll stick with my snippets though due to the following reasons: Intelephense requires that I type the -> i.e.. First, I type pages, then I type ->, then I select the property/method I want. Meaning, to get $pages->find('selector'), I need to type 3 times! And it doesn't give me the "" around the string 'selector'. Using the snippets, I only need to type once; e.g., pagesfind, hit tab and bam, I get the whole thing, $pages->find("selector"); With the snippets, I get the closing semicolon at the end of the statement. Not with intelephense With the snippets, I can use normal variable syntax; I don't use the Functions API ? Aah. This is because I had Auto Close Tag before support was included in VSC 1.16. Also, one has to enable it on editor.quickSuggestions > strings:true :-).
  7. Great! Oh no! That's because it is matching the > in the prefix value in the snippet. So, I should change this: "prefix": "pages->find(\"selector\")" to this: "prefix": "pagesfind(\"selector\")" Thanks for catching this, but hey, you shouldn't be typing HTML closing tags! ? VSC extensions should do that for you. See Auto Close Tag. It can do this: Have a look at Auto Rename Tag as well (it acts up sometimes though). Regarding ProcessWire variables, first check out intelephense (as per previous discussions earlier today). If it works for you, then no need for my snippets :-). I've gone back to my snippets atm since intelephense is not working for me ?
  8. I've tried intelephense and it's not working for me. Only PHP functions show up. Anything I might be missing? I'm on windows 7
  9. Not sure if this thread is still relevant? If it is, it seems cloning repeaters can be a pain ?? Btw, this: $block = $salespage->children("id={$duplicate_id},include=all")->first(); Can be shortened to this: $block = $salespage->child("id={$duplicate_id},include=all");
  10. A similar question regarding comparisons of the 3 main PHP intellisense extensions https://github.com/bmewburn/vscode-intelephense/issues/128
  11. @AndZyk. Thanks to you and @bernhard, I'll now try intelephense. Bottom line is the snippets I created have no advantage over intelephense from what I've read and seen :-).
  12. It does look nice! Felix's would struggle with variables from included files (something that worked in ST out of the box). It would also struggle with variables from new Page(), etc. If you try the intellisense of other languages such as JavaScript or Python, you'll be amazed. If I called something similar to $blog = $modules->get("MarkupBlog"), they will pick up on the methods and properties in MarkupBlog! Do you get that with intelephense or it isn't that advanced? I'll give it a shot though. Thanks for the heads-up.
  13. Intellisense has never worked for me with ProcessWire variables :-). It just doesn't pick. I use Felix Becker's. Edit: Aah, I see you use Intelephense. I tried it once but for some reason I cannot remember, I went with Felix's. Maybe I should try it again. Edit 2: I might have gone with PHP Intellisense based on download numbers. I'll try Intelephense and if it works, I'll go with that. I'll leave the Gists up though, for those who use PHP Intellisense.
  14. @AndZyk Attached, a quick and dirty job for Functions API, one for each style. $items = pages("template=basic-page"); style #1 $items = pages()->find("template=basic-page"); style #2 I don't know how style #1 works with (or should even work with) things like pages->count? I know style #2 could be pages()->count. Because of this, VSC will complain of duplicate keys since with the search and replace, we ended up with multiple pages(). (where we had pages->count; pages->find(), etc. :-). I also don't know about the WireArray stuff. I don't think those have functional api, no? They would have to be removed from these snippets. I haven't tested much. If you are able to test, I can upload to separate Gists, once cleaned up, thanks. vsc_pw_functional_api_style-1.json vsc_pw_functional_api_style-2.json
  15. I can make a separate version for Functions API. Looks like a simple regex job Maybe not soon ?.
  16. Yes, you can create your own formatter. Not sure about the learning curve though. Maybe start with an existing extension and build off that. I love notepad++ and use it daily....but not for coding. For text manipulations and a poor man's 'sticky notes', it works for me. But you can't even begin to compare it to VSC. They are two different beasts ?.
  17. I' not sure actually. I've just tried the <?= ... ?> and although they are highlighted, the editor shows a syntax error. <?...?> work OK. I'm not sure if there's an extension to handle the tags you want. I'd still urge you to give VSC a try ?and maybe even ditch those short tags; I've never liked them :-).
  18. ProcessWire API Visual Studio Code Snippets Here is a Gist of all (?) ProcessWire public API snippets for VSC. This is generated from the ProcessWire Cheatsheet. Some stuff needed manual cleanup. I also removed the stuff from the selectors section. I could have missed something, please let me know. Please note this is a complete, well-formed JSON file. If you need to copy to your existing VSC snippets file (most likely your php.json), remember to remove the top and bottom outermost curly braces. One great thing about VSC is that it doesn't care much about typos; fuzzy search will find what you meant to type. E.g., 'cnf' will match 'config'. Maybe the JSON file is too long, I don't know, but sometimes the snippets' descriptions don't show up. The snippets are for use in a template file (i.e., no auto $this->), but you can still use it in a module and/or modify it to suit such needs. Hope you find it useful :-). Demo
  19. Hi @DxJR, Welcome to the forums and ProcessWire. Thanks for testing the module. What ProcessWire version are you using? A recent ProcessWire update seems to have broken the module. I noticed this when setting up some sites last week. I've not had a chance to debug it yet. I am quite busy at the moment and don't know when I'll look into it. Until then, please do not to use the module in production sites. I'll update the first post.
  20. Maybe create a Process Module (say, Manage Users) that only Superusers and Site Admins can view. Create a simple GUI >>> add foo, add bar, etc. Behind the scenes, you use the API to manage users, roles and permissions. Obviously, you restrict the roles, permissions, etc that the Site Admins can manage. It might seem like re-inventing the wheel, but you avoid the red lines/pitfalls you've mentioned (site admins seeing modules, etc). Just my 2p.
  21. OK, I get you. My understanding is that you will have ONE colors page which will hold ALL your colours whereby the different colours are defined within the repeaters? You then want these colours (the ones that are usable) to be individually selectable within page reference field product_color? Meaning your page field will show brown,green,red, etc? Unless I've missed some recent PW feature, you can't do that. Only pages are selectable in page reference fields. So, you would have to change your approach. Let me know if I'm still missing the mark :-).
  22. Hey @jothanne, Welcome to ProcessWire/the forums. I don't get your setup entirely. Do you have a repeater nested within a repeater? i.e., is type_repeater a repeater field that also contains the repeater color_repeater? Normally for the sort of logic you are after (for page fields), you can use the Custom PHP Option (see the input tab of your page field product_color). I'm not sure this solves your problem though as I don't fully grasp your setup.
  23. In future, will the editors, when they create a new project page, be inputting the display title themselves? Yes ? Yes. The defaults are you start from the beginning (0) and you get everything (limit=0 aka, no limit). In my example, I wanted to start from 2 (not a good example, I know) A better example is, assuming I had done a batch before, say the first 100 pages. In the next batch, I'd start from start=101 and limit=100..meaning, I do 100 at a time. There's a way to automate this, but that's a lot more code :-). Not quite. It would work though, but since you want to apply to all projects pages, there is no need to enter a start and limit. The following would do: generateDisplayTitle('display_title','projects'); It should be the name of the template. In my example, it was 'projects'. Adapt to your needs, so yes, 'project' in your case. But it can be any template with a display_title (or whatever you've named the field) field whose pages you need to edit. Test on a local install first ?
  24. I'd leave the title field as is. Names (urls) are generated from the title when you create a page. If your pages are live, then better leave the title as is. How many? This affects how you should run the script below Not a great idea! No need for html here. This is a better way IMO That's why we have the API :-). See script below. TEST BEFORE USE IN PRODUCTION SITE! Log in as superuser Copy and paste the following code into a template file, maybe the one used by your home page. Visit a page using the template in #2 Check if things went OK Delete code from template file when done If you have lots of project pages, make use of the start and limit parameters. /** * Copy title field contents to a specified text field on the same page. * * @param string $fieldName Name of the field to edit. * @param string $templateName Name of the template file whose pages we are editing. * @param integer $start Start of $pages->find(). * @param integer $limit Limit of $pages->find(). * @return void */ function generateDisplayTitle($fieldName, $templateName, $start=0, $limit=10) { // only superusers allowed! if(!wire('user')->isSuperuser()) return; // fetch a limited number of pages $editPages = wire('pages')->find("template=$templateName,start=$start,limit=$limit"); # we found pages if($editPages->count) { foreach ($editPages as $editPage) { $editPage->{$fieldName} = $editPage->title; $editPage->of(false); $editPage->save($fieldName); $editPage->of(true); } } } // call the function - here, we start at index 2 and limit to 3 pages // the field we want to copy content to is called 'display_title' // the template of the pages we want is 'projects' generateDisplayTitle('display_title', 'projects', 2,3); # not many pages use (i.e. do all) #generateDisplayTitle('display_title', 'projects');
  25. Of course. Silly me ?. Thanks @adrian
×
×
  • Create New...