Jump to content

Piqsel

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Piqsel

  1. That did the trick! Forgot about having to use wire('pages') in functions. Thank you so much for your time.
  2. Hmmmm, tried changing it to the following $selector = "template={$page->children->first()->template->name}, limit=24, " . trim($selector, ", "); but now I get the error "Undefined variable: page" on the same line. Any ideas? Thanks for your patience :).
  3. Thanks for helping me! I tried changing the follwoing line: $selector = "template=car, limit=24, " . trim($selector, ", "); to $selector = $page->children->first()->template->name . trim($selector, ", "); but that returns error "Undefined variable" for that specific line. When I echo the "$page->children->first()->template->name" I get the correct template though so I guess I'm missing something.
  4. Hi, Sorry in advance for a long post and the lack of knowledge :), but I was wondering how I would go about to modify the scyscraper profile to be used for several different "objects". Right now I have the following tree structure and templates: - Cars (basic-page.php) - New cars (cars.php) - BMW M3 (car.php) - BMW M5 - BMW M7 - Used cars - Volvo S60 - Volvo S90 - Volvo XC90 - Motorcycles (basic-page.php) - New motorcycles (motorcycles.php) - List of new motorcycles (motorcycle.php) - Used motorcycles - List of used motorcycles To render new cars I have the following functions (based off of the Scyscraper profile): function findCars($selector) { $validSorts = getValidSorts(); $sort = sanitizer('name', input()->get('sort')); if(!$sort || !isset($validSorts[$sort])) $sort = 'name'; if($sort != 'name') input()->whitelist('sort', $sort); $selector = "template=car, limit=24, " . trim($selector, ", "); if(strpos($selector, "~=") === false) $selector .= ", sort=$sort"; $cars = pages($selector); return $cars; } function renderCarList(PageArray $cars, $showPagination = true) { $pagination = ''; $sortSelect = ''; $items = array(); if($showPagination && $cars->count()) { $pagination = renderPagination($cars); $sortSelect = renderCarListSort(); } foreach($cars as $car) { $items[] = renderCarListItem($car); } $selector = (string) $cars->getSelectors(); if($selector) $selector = makePrettySelector($selector); $out = files()->render('./includes/car-list.php', array( 'cars' => $cars, 'items' => $items, 'pagination' => $pagination, 'sortSelect' => $sortSelect, 'selector' => $selector )); return $out; } function renderCarListItem(Page $car) { $images = $car->get('images'); if(count($images)) { $thumb = $images->first()->width(200); $img = $thumb->url; } $car->set('unknown', '--'); $out = files()->render('./includes/car-list-item.php', array( 'car' => $car, 'url' => $car->url, 'img' => $img, 'title' => $car->title, 'price' => number_format($car->price, 0, ' ', ' '), 'price_monthly' => number_format($car->price_monthly, 0, ' ', ' '), 'year' => $car->get('year|unknown')->title, 'milage' => $car->get('milage|unknown'), 'fueling' => $car->get('fueling|unknown')->title, 'gearbox' => $car->get('gearbox|unknown')->title )); return $out; } To render the cars I have the following on cars.php: region('main', files()->render('./includes/hero.php') . renderCarsList(findCars('')) ); This works fine, but it seems very redundant to make new functions for every type of vehicle when the listing pages of the vehicles looks almost exactly the same. What I would like to do is change the above functions to be something like findVehicles, renderVehicleList and renderVehicleListItem. I was wondering if this is possible to accomplish by simply changing the $selector from using template=car to instead somehow get the current page childrens template. So on the cars page the selector template becomes car, on motorcycles page the selector becomes motorcycle etc. I tried fiddling around with $page->child->template but can't get it to work. Maybe I should change strategy altogether? Any advice or suggestions will be much appreciated.
  5. I would also like to know if its possible to load images with this module?
  6. Hi, and thank you for this module! I've been trying get the feature/devns branch to work with PW 3.0.14 but ran into a problem. I try to render the form as below: 82 <?php echo $modules->get('SimpleContactForm')->render(); ?> and the form shows up but with the following message: Notice: Trying to get property of non-object in /site/templates/_main.php on line 82 If I fill in the form and press send I get a "Your contact request has been send successfully!" message, and when I check the Simplecontactform-log it has a success entry. It seems like it's working so why do I get the error message on line 82? Thanks in advance!
  7. Yes, forgot to say that the number_format is working also .
  8. Wow, what a great community! I'm embarrassing to say that Adrian was spot on when he asked if the field had a label defined . The products has 25+ custom fields and I labeled all but, of course, the price field. $product->fields->product_price->label did work so thank you all for helping me!
  9. Hi Adrian and thank you for your quick reply! I tried the above but it just output a colon, so I guess I'm must be doing something wrong somewhere. Cant figure out what though since images and everything else works as it should.
  10. Hi, Just discovered Processwire and instantely got a new favorite CMS. Finally something that doesn't feel so bloated like some others. Anyway, I started working on a little product showcase and have a question about field labels and how to output them. Is there a way to get a certain field label so that I (in the example below) can replace "Price:" with something like {$product->product_price->label}? Also, could I use number_format directly on {$product->product_price}, or do I have to make a variable like so: $nf_price = number_format($product->product_price, 0, ' ', ' '); <?php function productList(){ $products = wire("pages")->find("parent=/products/"); $out =" "; foreach($products as $product){ $out .="<article class='six columns'>"; $out .="<img src='{$product->images->first()->url}'>"; $out .="<a href='{$product->url}'><h1>{$product->title}</h1>"; $out .="<span>Price: </span><span>{$product->product_price}</span>"; $out .="<span>Stock: </span><span>{$product->product_stock}</span>"; $out .="</article>"; } echo $out; } ?> Enough with dumb questions for now, but be prepared for a lot more in the near future .Thanks in advance!
×
×
  • Create New...