Jump to content

matjash

Members
  • Posts

    14
  • Joined

  • Last visited

Recent Profile Visitors

1,128 profile views

matjash's Achievements

Jr. Member

Jr. Member (3/6)

5

Reputation

2

Community Answers

  1. Thank you. This works. I was thinking in the right direction. I just hoped that there is some better solution, cause my code get's little ugly this way. I have to define javascript window.variable which I pass to javascript file (in strict mode), which calls for ajax response. Cookie should work too I guess. If I set a cookie on language change, but this also woldn't be neat solution.
  2. Does anybody know how to output AJAX response in multilingual site. On the home page I call another page which has if($config->ajax) {...} code. The response is always in the default language.
  3. Thanks again everything is working fine. I'm just fine tuning the form output. I'm pasting my code so someone with same problems can quickly view how to customize it based on your initial answer I had to add $childFinish since my child output was in UL tag: <?php function getComments($comments, $page, $parentID = 0, $reply = true, $child = null, $childFinish = null) { $out = ""; foreach($comments as $comment) { if($comment->parent_id == $parentID) { $reply = ($reply == true) ? "<a class='comment__reply js-comment-reply CommentActionReply comment-reply-link' data-comment-id='{$comment->id}' href='#Comment{$comment->id}'>Reply</a>" : ""; if($comment->status < 1) continue; $cite = htmlentities($comment->cite); $text = htmlentities($comment->text); $userID = $comment->created_users_id; $u = wire("pages")->get($userID); $name = ($u->displayName) ? $u->displayName : $u->name; $date = date('m/d/y g:ia', $comment->created); $out .= $child . " <li class='comment__item'> <div class='comment__item-body js-comment-item'> <div class='comment__avatar'><img src=" . wire('config')->urls->templates . "rs-template/assets/media-demo/avatars/01.jpg alt=''></div> <div class='comment__item-right'> <button class='comment__item-btn'>Edit</button> <button class='comment__item-btn'>Delete</button> </div> <div class='comment__info'><span class='comment__author'>" . $cite . "</span><span class='comment__date'>" . $date . "</span> <div class='comment__content'> <p>" . $text ."</p> </div> " . $reply ."</div> </div> <!-- end of block .comment__item-body--> "; $out .= "</li>" . $childFinish; $out .= getComments($comments, $page, $comment->id, false, "<ul class='comment__children'>", "</ul>"); } } return $out; } echo getComments($page->blog_comments, $page); ?>
  4. Thank you the display is perfect, now i need to customize the reply button but i have a problem also with default method if I render form via renderAll() method as stated in documentation. The reply doesnt work. On click the hashtag gets comment id, and window moves to input form. Which functionality should then happen? Does the original message gets send to the cookie or does the form get some data from comment. Js and css gets loaded correctly.
  5. I need some help with threaded comments. 1. I want to use custom markup and display only 1 level deep, but I dont know how to iterate through array to output correctly. 2. I tried the general example by using function renderALL(), but the reply doesn't work. (I have put css in head and script to body) I tried with this code but it doesn't work because it double prints comments with children: <?php foreach($page->blog_comments as $comment) { if($comment->status < 1) continue; // skip unapproved or spam comments $cite = htmlentities($comment->cite); // make sure output is entity encoded $text = htmlentities($comment->text); $date = date('m/d/y g:ia', $comment->created); // format the date //If comment has children display parant and child if ($comment->children->count >= 1) { foreach ($comment->children as $children) { $cite2 = htmlentities($children->cite); // make sure output is entity encoded $text2 = htmlentities($children->text); $date2 = date('m/d/y g:ia', $children->created); // format the date include('rs-template/includes/comments/commentL2.php'); } //Display only parent } else { include('rs-template/includes/comments/commentL1.php'); } } ?>
  6. Hi I wonder if there is someone with similar problem, i have a structure: home.php in site/templates <?php include("./rs-template/homepage.php"); in site/templates/rs-template/ i keep the homepage.php file, in that file is also include dir to:site/templates/rs-template/includes <!-- BEGIN HEADER-subpage--> <header class="header header--brand"> <?php include "includes/header.inc";?> </header> <!-- END HEADER-subpage--> The include file doesn't refresh on change. If I put my php to home.php everything is working fine. I created new homepage tamplate and after a while it started to work on homepage (when I renamed template). On subpage the problem exists. If you wonder why do I need separate template folder, because I try to develop webpage with 3 optional templates. Update: If the content on homepage change the include file gets updated. I just had wrong relative path of second include -> I lost one hour, because I don't know how the content was even displayed!
  7. Hi joshuag, I would like to know more about your projects. I've 2 years experience with pw and love working with it.

  8. It doesn't work for me: JqueryMagnific.js:4 Uncaught TypeError: e is not a function(anonymous function) @ JqueryMagnific.js:4(anonymous function) @ JqueryMagnific.js:4 FrontEndEditLightbox.js:77 Uncaught TypeError: Cannot read property 'defaults' of undefined I tried to disable other scripts but no success so far. Javascript is loaded before the end of body tag. I am using jquery-2.1.0.min.js I found the error. I had all the script added at the body tag. But the JqueryMagnific gets added at the head, so it was inserted before jQuery.
  9. I noticed that. The line stayed there from earlier testing. At that time the code wasn't put in an autoload module.
  10. I've found the error: $translateTxt = $page->getLanguageValue("default", "opis"); //Problematic line
  11. Can someone help me solve this one: I have a saveReady hook. It shold read default language field and on save translate it with yandex translate api. I've got it working if I put the value manualy but it doesn't get read if I input it as $page->opis public function init() { // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookBefore('saveReady', $this, 'translate'); //$this->pages->addHookAfter('save', $this, 'example2'); } public function translate($event) { $page = $event->arguments[0]; $this->message("Hello you changed {$page->opis}."); /*Api key for yandex translator*/ $key = "trnsl.1.1.20151103T231043Z.0a5368c915d3f2ea.1906616d49e10cfd99e499e1884cbc175178f28b"; /*Bootstrap pw*/ include "../index.php"; /*Translator script*/ include "code.php"; $translateTxt = $page->opis; //Problematic line //$translateTxt = "Ali deluje?"; //Working $translateLang = 'sl-en'; $translator = new Translator($key); $translation = $translator->translate($translateTxt, $translateLang); $event->return = $page->opis->setLanguageValue("en", $translation); }
  12. Thank you guys. In the meantime I found another solution which suits my need: public function init() { $this->addHookAfter('Pages::saveReady', $this, 'afterSaveReady'); } public function afterSaveReady($event) { // Get the soon to be saved page object from the given event $page = $event->arguments[0]; // Sample condition and changes if($page->template == "nepremicnine-vnos" && !$page->isTrash()){ //Price $cena = $page->cena; //Old price $stara = $page->cenaStara; $znizano = $page->znizano; //Checkbox to display old price, if not checked on save copy price to oldPrice if($znizano == 0) { $page->set("cenaStara", $cena); $page->save("cenaStara"); } } } } I will look into the way of track field changes. It seems usefull for future development.
  13. I need some help. I have fields price and priceBefore I want to copy price value on save to priceBefore field. public function init() { $this->pages->addHookAfter('save', $this, 'hookSave'); //$this->pages->addHookAfter('added', $this, 'hookAdded'); } public function hookSave(HookEvent $event) { // this function called any time a page is saved (whether new or not) //$page = $event->object; $page = $event->arguments[0]; // now you can access anything from the $page if ($page->template == "nepremicnine-vnos") { // get value from price field and copy to priceBefore/cenaStara $page->cenaStara = $page->cena; $page->save("cenaStara"); } } I 've read some examples but I just can't make it work. Is it maybe better to put it in InputField::render? public function init() { // add before-hook to the inputfield render method $this->addHookBefore("Inputfield::render", $this, "renderField"); } public function renderField(HookEvent $event) { // // get the current field $field = $event->object; if($field->name == 'cenaStara' && $field->value == '' ) { $field->cenaStara = $field->cena; $oldPrice = $field->cenaStara $field->set('value', $oldPrice); } }
  14. Than you for guidance. I've decided to let go the options to search by other countries for now, but I have found a way, how to. I made countries and regions as $page field select and then put selector "country=england" or "region=westminster" ... I just felt it more natural to catogarize them by pages for editing purposes. Now I have every relaestate-input in realestate category.
  15. Hi I'm quite new to processwire but I already fall in love with it. But now I'm struggeling with a problem for more than a week, since I'm not very good at PHP programing, but am willing to learn. I want to make a real estate page and I want to focus on the search capabilities of processwire. I made a structure Real estates (template=realestates) - Country 1 (template=country) - Region 1 (template=region) - Product 1 (template=realestate-input) - Region 2 - Product 2 - Country 2 - Region 3 - Product 3 - Country 3 Hidden Options - Rooms ( to use as page field in template=realestate-input) - 1 room - 1,5 room - ... - Type ( to use as page field in template=realestate-input) - Appartement - House - Holiday house I've looked at skyscrapper search examples but I can't crack it to fit in my case. I've made a form which generates Country's and Region's: <form id='skyscraper_search' method='get' action='<?php echo $config->urls->root?>iskanje/'> <h3>Real estates</h3> <p> <label for='search_keywords'>Keywords</label> <input type='text' name='keywords' id='search_keywords' value='<?php if($input->whitelist->keywords) echo $sanitizer->entities($input->whitelist->keywords); ?>' /> </p> <p> <label for='search_Location'>Location</label> <select id='search_Location' name='location'> <option value=''>Vse</option><?php // generate the location options, checking the whitelist to see if any are already selected foreach ($pages->get("/nepremicnine/")->children() as $country) { $selected = $country->name == $input->whitelist->location ? " selected='selected' " : ''; echo "<option$selected value='{$country->name}'>{$country->title}</option>"; foreach ($country->children() as $Location) { $selected = $Location->name == $input->whitelist->location ? " selected='selected' " : ''; echo "<option$selected value='{$country->name}/{$Location->name}'> - {$Location->title}</option>"; } } ?> </select> </p> <p><input type='submit' id='search_submit' name='submit' value='Search' /></p> </form> On click I want to make selector look for template=realestates-input on selected parent of upper form. The following code works for regions, becouse their childrens are "realestate-inputs", but if I select country I want to display all realestates in every region. <?php // most of the code in this template file is here to build this selector string // it will contain the search query that gets sent to $skyscraperList $selector1 = ''; // we use this to store the info that generates the summary of what was searched for // the summary will appear above the search results $summary = array( "location" => "", ); $location = $input->get->location; echo "<br>" . $location . "<br><br>"; // if a location is specified, then we limit the results to having that location as their parent if($input->get->location) { //$location = $pages->get("/realestates/" . $sanitizer->pageName($input->get->location)); $location = $pages->get("/realestates/{$input->get->location}"); if($location->id) { $selector1 = "parent=$location, "; $summary["location"] = $location->title; $input->whitelist('location', $location->name); } } //$selector1 .= "template=realestates-input, "; $matches = $pages->find("$selector1,"); echo "<br>Found: " . count($matches) . " match<br>"; echo $selector1; foreach ($matches as $match) { echo "<br>" . $match->title; } When I'll crack this one I will only need to filter the search results based on selected options on realestates-input template. But also don't know how to make a selector for that. I would really appriciate any guidance to complete my task. Thank you
×
×
  • Create New...