Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. Thanks for the quick solution, @adrian. I'm not sure if we're talking about the same thing, but docs mention that these methods modify other siblings to accept new order.
  2. @louisstephens you don't really need ajax, you can use History API to change address bar and browser history without refreshing https://stackoverflow.com/a/19279428
  3. @PWaddict after v3.0.46, there're $pages->sort() and similar methods to move pages and change their order I haven't tried this, but from what I understand from the docs, $pages->sort($pageToTop, 0); moves a page to top of its siblings. https://processwire.com/blog/posts/pw-3.0.46-stocking-stuffers/
  4. No worries, good to know you got it all up and running For reference here's how you add/edit environment variables on Windows 10 https://superuser.com/a/989665
  5. At the top of your template files, inside a <?php ?> tag, preferably before outputting anything. You can't send a new header after you've already sent them (i.e. output any data) For example: (in your home.php) <?php namespace ProcessWire; $session->redirect("/about/");
  6. There's $session->redirect($url) https://processwire.com/api/ref/session/redirect/ You can use it in conjuction with $page->url($params) to generate any type of page url for redirection https://processwire.com/api/ref/page/url/
  7. Something like this? https://stackoverflow.com/questions/14961556/convert-one-dimensional-array-into-a-multi-dimensional-array
  8. Is it possible to use Pagefile class independent of a Page or Pagefiles class? Looking at Pagefile::__constructor, it needs both $page and $pagefiles to instantiate. I guess they're limited to internal use only. Probably because they're saved in DB
  9. Do you have template cache enabled? When you're logged in on your PC, you wont notice anything, because cache will be disabled but visiting the page as guest on an iOS device you might be getting a cached version with the old content and old URLs. Although I see you've tried using query strings, I often use this function to create cache busting URLs for CSS & JS. If the file is modified, correct modified time string is appended to the URL and browser downloads newer version. No need to increment version manually. /** * Adds file modified date as query string and returns URL to given asset. * * * @param $relPath string File path relative to /site/templates/, such as "assets/css/style.css" * @return string URL with cache busting query parameter */ function assetUrl($relPath) { $fullPath = wire()->config->paths->templates . $relPath; $modified = filemtime($fullPath); $url = wire()->config->urls->templates . $relPath . "?v=$modified"; return $url; } In your templates, you can load a script like so: <script src="<?= assetUrl("assets/js/main.js") ?>"></script>
  10. Is the error permanent? Unless it gives red errors, I wouldn't worry. If git is installed, you should be able to access it from command line. Once choco installs a program and adds it to PATH, it runs a bat file called refreshEnv.cmd to refresh the PATH variable. Close (all) command prompts and reopen, then try running git.
  11. Sorting by published works for the last two years or so. (Not sure about before that or about PW 2.6 though) $pages->find('template=MyTemplate, limit=15, sort=-published') most certainly works.
  12. I use chocolatey to install packages on Windows. https://github.com/chocolatey/choco/wiki/Installation It's similar to apt on Debian or brew on Mac Here's the package for git https://chocolatey.org/packages/git.install
  13. This code seems to render a repeater matrix, are you using field render functionality? Like echo $page->render->matrix_field which uses /site/templates/fields/matrix_field.php? If so, you can divide your code into multiple files for each matrix type and put those under /site/templates/fields/matrix_field/type1.php and so on. https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/#processwire-3.0.5-introduces-field-rendering-with-template-files There's also wireRenderFile() to render a template file with given variables and return string output. I use it a lot in my templates. https://processwire.com/blog/posts/processwire-2.5.2/#new-wirerenderfile-and-wireincludefile-functions I tried to clean up your code. Some remarks: If you know there's only one page in a wirearray, you can get it with $arr->first Use if(! $some_condition) return; to reduce nesting You can open and close <?php ?> tags to give yourself some flexibility, so you wont have to put your HTML inside PHP strings. Anything you put between php tags will be echoed. <?php namespace ProcessWire; // dont show if user is not superuser if (!$user->hasRole('superuser')) return; // dont display partial markup if there are no related products if(!$page->related_products->count) return; // used for picking a random product from related products $randomSelector = 'template=product, sort=random, limit=1'; ?> <div class='uk-section uk-section-muted section-related'> <div class='uk-container'> <h3>Related Products</h3> <div class='uk-grid-match uk-child-width-1-4@s' uk-grid> <?php foreach ($page->related_products as $matrix_item): ?> <?php $randomProd = $matrix_item->related_random->children($randomSelector)->first; ?> <div class='rel-prod-ov-wrapper'> <a href='<?= $randomProd->url ?>'> <img src='<?= $randomProd->images->first()->url ?>' class='rel-prod-preview'> </a> <div class='rel-prod-ov-text'> <span class='rel-preview-title'><strong>Part No:</strong> <?= $randomProd->title ?></span><br/> <?= $randomProd->prod_summary ?> <a href='<?= $randomProd->url ?>' class='uk-icon-button rel-icon-linky' uk-icon='icon: chevron-right'> <!-- THERE SHOULD BE SOME TEXT HERE --> </a> </div> </div> <?php endforeach; ?> </div> </div> </div> Not sure if this works, there are some parts I couldnt make sense, but it should give you some ideas. If you give more info, I might be able to help you better
  14. I meant explode() method, but wrote extract() instead https://processwire.com/api/ref/wire-array/explode/ And thankfully, that works @jploch. $tags = $page->options->explode('title'); $json = htmlspecialchars(json_encode($tags)); echo "<div data-category='$json'> ... </div>"; Thank you for the heads up @kongondo
  15. location /demo/ { try_files $uri $uri/ /demo/index.php?it=$request_uri; } Does this work? http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri
  16. $imgs = $page->images->getArray(); $chunks = array_chunk($imgs, 15); foreach($chunks as $chunk) { foreach($chunk as $img) { /* ... */ } } http://php.net/manual/en/function.array-chunk.php Unfortunately, there doesnt seem to be a chunk method available for WireArray class https://processwire.com/api/ref/wire-array/
  17. I assumed options field to return a type of WireArray, I've checked, it returns a SelectableOptionArray which extends WireArray, but I guess some methods are modified I tested this one and it works $tags = $page->options->getValues(); $tags = array_column($tags, 'title'); $json = htmlspecialchars(json_encode($tags)); echo "<div data-category='$json'> ... </div>"; In your JS, you can retrieve the array back like this let items = document.querySelectorAll('.item'); // filter items by category let xItems = items.filter(it => { let tags = JSON.parse(item.dataset.category); // tags is an array return tags.indexOf('category-x') > -1; })
  18. Happy to be of help. IIRC, there used to be a "mark as solved" button. I remember seeing a green answer on the top. I guess it's been removed. In the meantime there's the like button.
  19. As an alternative to using classes to filter, you can convert categories into JSON and inject into HTML as data attributes. I haven't tried this, but it should work. $tags = $event->options->extract('title'); $json = htmlspecialchars(json_encode($tags)); echo "<div data-category='$json'> ... </div>"; https://stackoverflow.com/a/9430472
  20. Since all these cards have "find out more" links, they appear to be linked to a page with more content. Start with creating a page field, say "servicePages" and add that to the template of the page that will show these cards. Then add a Textarea field to "service" template, say "serviceSummary", to store the summaries (or get it from another field instead). Then add the service pages that need to be shown in cards to servicePages field. You can then iterate over them and build your markup <?php foreach($page->servicePages as $sp): ?> <div class="service-card"> <img class="service-card__img" src="<?= $sp->images->first->size(300,200)->url ?>"/> <h2 class="service-card__title"><?= $sp->title ?></h2> <p class="service-card__summary"><?= $sp->serviceSummary ?></p> <a class="service-card__link" href="<?= $sp->url ?>">Mehr Erfahren</a> </div> <?php endforeach; ?>
  21. If you don't want to call a method, or want to use it in a string, you can use $page->header_OR_title too. echo "Text: $page->headline_OR_title"
  22. I've looked at the lines given in the error report, they all point to $language ($user->language) but can't access it. If you can access your database (adminer, PHPStorm, phpMyAdmin etc) examine field_language table. Confirm that your current user (admin = id: 40) has a language associated with it. Also see if $pages->get(<languageid assc. with admin>) returns anything
  23. I've never had this problem but I'd swap /wire/ with a new one and move templates to elsewhere. Then I'd add template files one by one to find where the problem is.
  24. Not a solution but on form pages I disable template caching and opt for WireCache class for caching small bits of markup, like fetching pages and creating an <select> etc. https://processwire.com/api/ref/wire-cache/
  25. Can you give a bit more context to this piece of code? Where does $image come from? Does image display on the front end (or does url show up correctly)?
×
×
  • Create New...