-
Posts
6,808 -
Joined
-
Last visited
-
Days Won
159
Everything posted by Soma
-
New to Hooks, trying to wrap my head around the syntax
Soma replied to creativejay's topic in Getting Started
Actually saveReady is an after hook and it's especially useful as you know that the page is saved right after that. So no endless recursion and you don't need to save the page. With a before save hook you don't know if an error will occur. Also no need to set the page back to the argument after you done with manipulating the page. So lots of mis-infos here.. Means the best answer isn't the best really Edit: removed the 'Solved' flag for now. -
I see. Yes that's somewhat different to what WireArray does, but you're way is fine then. You can add your own method to PageArray using hook then instead of a new class. wire()->addHook("WireArray::addUnique", null, function($event){ $item = $event->arguments(0); if($item instanceof WireArray){ foreach($item as $p){ if(!$event->object->has($p)) $event->object->add($p); } } else { if(!$event->object->has($item)) $event->object->add($p); } }); $pa = new PageArray(); $pa->add($pages->find("template=basic-page")); $pa->addUnique($pages->get("/about/")->children); $content .= $pa;
-
$pa = new PageArray(); $pa->add($pages->find("template=basic-page")); // 1001 at the first pos $pa->append($pages->get("/about/")); // 1001 at the last position now (unique) echo $pa;
-
Doesn't matter if you add a page or a page array to a page array it will always contain only unique pages.
-
Well, PageArray is already unique. Considering this example, you'll end up with 1 entry in PageArray: $pa = new PageArray(); $pa->add($pages->get("/about/")); $pa->add($pages->get("/about/")); echo $pa;
-
any good way to redirect to original url from a custom login form ?
Soma replied to adrianmak's topic in General Support
@ESRCH That login code will throw error if you login 3 times with wrong credentials... I already tried to put a note in those various (dozens already and lost track of) threads that use this "exact" frontend login code, which works but has one flaw. Problem is that once the login throttle kicks in you're left with a exception error. It's not obvious and I think posting that code in the forum over and over just creates problems in the long run for everyone copy paste such code. Funny thing is that the code originally is from Ryan himself. Either Ryan should change the behaviour of the throttle code or you need to use this code instead with a try catch to catch the login throttle error: if ($user->isLoggedin()) { $session->redirect($pages->get('/')->url); } if ($input->post->user && $input->post->pass) { $username = $sanitizer->username($input->post->user); $password = $input->post->pass; try{ $u = $session->login($username, $password); if ($u) { if ($redirectUrl = $session->get('redirect')){ $session->remove('redirect'); $session->redirect($redirectUrl); } else { $session->redirect($pages->get('/')->url); } } else { $error = "Wrong username or password. Login failed."; } } catch(Exception $e){ $error = $e->getMessage(); } } -
I think you're looking for repeater or pagetable field https://processwire.com/talk/topic/6417-processwire-profields-table/page-2#entry63119 And for PageTable there's a extended version. https://processwire.com/talk/topic/7459-module-pagetableextended/
-
I have used this to redirect to language the user was in. if(wire("input")->get->logout == 1){ $lang = wire("user")->language; wire("session")->logout(); wire("session")->redirect(wire("page")->localUrl($lang)); }
-
redirect to a URL in the access tab of a template
Soma replied to adrianmak's topic in Getting Started
Read the notes there: Optional: In your URL, you can include the tag '{id}' (perhaps as a GET variable), and it will be replaced by the requested page's ID number, if you want it. Edit: maybe you can use the id somehow. But maybe a better option would be to have some code in those template to check for if the user is logged in an redirect with API if(!$user->isLoggedin()) $session->redirect($pages->get(1230)->url); // 1230 if of login page and the url will be in the language the user is viewing the site. -
You would use the beautifier translate option (Sanitizer::translate) to have sanitizer use the special char conversion $name = $this->sanitizer->pageName($pageName_en, Sanitizer::translate); The chars are defined in the PageName module config screen, where you can set conversion for each char like "ö => oe", default is "ö => o"
-
Why do you need the "../"? Shouldn't it be absolute from domain root "/en/contact/contacts-done/" Since you say you loose the post vars, try to inspect in console while posting, it tells you if it get's redirected. You just have to find the correct url that doesn't do it. Usually you just use $page->url in the language you are and post it to itself, then redirect after it was successful to show a success message. It's called PRG pattern http://en.wikipedia.org/wiki/Post/Redirect/Get to avoid getting send again when using back button or refresh etc. Edit: Just wanted to mention since I don't think it's good to post a contact form to a "done" page, what if there's form errors you want to show the form again?
-
I don't know. How does the english url look then?
-
You'd link to the wire directory from wherever folder on your server. This doesn't work cross server. It's like an like a shortcut linking to a folder. So you create a symlink inside each domain where the wire folder would be, and the link points to the real wire folder. There's tons of infos on the internet just search http://en.wikipedia.org/wiki/Symbolic_link
-
<form role="form" action="../<?php $config->urls->root;?>contatti/contatti-invio/" method="post" > will be like... ..//contatti/contatti-invio/ ? Apart from that you have the italian url here so I'm not sure how you get the english one?
-
Actually it would be nicer if those avatars would link to the developer. Instead of justhe a picture.
-
You'll find all infos here http://processwire.com/api/multi-language-support/multi-language-fields/ $page->title is a string and not an object, so you need to turn off outputformatting first for the page.
-
One way is just symlink the wire directory into your websites directory.
-
https://packagecontrol.io/search/processwire
-
If you have template cache enabled you have additonal options appearing for defining GET or POST variables on which cache is not enabled. So enter some GET or POST vars you have in your form and it works.
-
I would try something like this: http://stackoverflow.com/questions/8432601/wamp-xampp-localhost-responding-very-slow
-
Must be something with you locall server. Sometimes excessive virtual hosts or inefficient hosts settings can cause slowdown. I wouldnt look in PW.
-
I think kongondo is close You can build top level entries using a PageArray. Only top level items are supported, once MSN got a PageArray it will recursively parse the tree from those top level entries. You could do this $items = new PageArray(); // add pages to PageArray $home = $pages->get("/"); $items->add($home); $events = $pages->get("/events/"); $items->add($events); $photos = $pages->get("/photos/"); $items->add($photos); $options = array( "selector_field" => "nav_selector" ); $nav->render($options, null, $items); but now make use of the "selector_field" option https://github.com/somatonic/MarkupSimpleNavigation#added-support-for-nav_selector-propertyfield-and-selector_leveln-new-in-121 default it is "nav_selector". When MSN finds a page with this property (either field or added at runtime) it will take that value as a selector to find/filter the children (if it has any). So if you want to have a custom selector on the "/events/" page it would look like this: $items = new PageArray(); // add pages to PageArray $home = $pages->get("/"); $items->add($home); $events = $pages->get("/events/"); $events->nav_selector = "limit=5, sort=-eventdatefield"; // define a selector $items->add($events); $photos = $pages->get("/photos/"); $items->add($photos); $options = array( "selector_field" => "nav_selector" ); $nav->render($options, null, $items); Now adding a additional item at the end is something I would add using JS (jquery). And also let the "Events" top menu entry link to the full list anyway. To get something to target the JS script you could use "inner_tpl" with a placeholder to add name or id to ul's and add that to the options array: $options = array( 'selector_field' => 'nav_selector', 'outer_tpl' => '<ul id="nav">||</ul>', 'inner_tpl' => '<ul id="{name}">||</ul>', ); Then do something like this with JS $("#nav ul#events").append($("<li><a href='/events/'>more</a></li>"));
-
Cache entire page except some part of it? Approaches?
Soma replied to Aleksey Popov's topic in General Support
Just thinking about it again jan's example, I think you guys are right in that if the php is in the cached template itself it wouldn't work as that code would never get executed, but remember that you can define GET vars on template settings, where when present to not cache the page. But you can also use a page for those calls without caching or use a php script bootstrap PW. Considering using template cache with a js inline call to a url that is current page with a GET var "mysnippet". Enter a cache time and add "mysnippet" to the "Cache disabling GET variables" appearing underneath. Now consider this snippet: $content .= "<script src='{$page->url}?mysnippet=bit'></script>"; if($input->get->mysnippet == "bit"){ header("Content-Type: application/javascript"); echo "document.write('<div class=\"bit\">');\n"; foreach($page->images->find("sort=random") as $img) echo "document.write(\"<img src='$img->url'>\");\n"; echo "document.write('</div>');"; exit(); } Will output random sorted images from the page in a template cached page. Edit: This only works when you use delayed output, hence the $content .= opposed to the direct echo "..." inside the condition, since this allows you to exit the script and not get other markup output before or afterwards. Same example $content .= $page->body; $content .= "<script src='{$page->url}?mysnippet=bit'></script>"; if($input->get->mysnippet == "bit"){ $images = ''; foreach($page->images->find("sort=random") as $img) { $images .= '<img src="' . $img->url . '">'; } header("Content-Type: application/javascript"); echo <<<_MKP document.write('<div class="bit">$images</div>'); _MKP; exit(); } $content .= $page->sidebar; -
Cache entire page except some part of it? Approaches?
Soma replied to Aleksey Popov's topic in General Support
Why shouldn't jan's example not work? I used a similar tchnique just recently. The image src is just a static url to return a random image. Of course in this case it's only good to serve one image src, limited to whatever image, but I think most of the time theres a need to do a little more with little junks of HTML. That's where js or str replace come in next. -
Cache entire page except some part of it? Approaches?
Soma replied to Aleksey Popov's topic in General Support
Most of what we do in templates has little to do with Pw solution. 99 is plain php js HTML and css. There's no Pw out of the box way. If I understand correctly you enable template cache for whole page but want a little part dynamic. So you're left with js or street replace output with php (again not pw). Using markup cache might be possible with an easy template but don't think worth of caching all 'around' that little dynamic part. Also markup cache has a fixed expire time you set and not by rules like when a page updates. If you're afraid of js I would try catching output with hook on Page::render and str_replace the parts you need. Once using procache instead of template cache eBen this won't work cause no php and mysql. So you're left with js again.