Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

22 Excellent

About rash

  • Rank
    Full Member

Profile Information

  • Location
    Stuttgart, Germany

Recent Profile Visitors

944 profile views
  1. rash

    Hanna Code

    Is it possible to pass session vars immediately in Hanna Code? Let’s say, I include two PHP files file_1.php and file_2.php via Hanna Code input in a textarea. When I set $session->foo = "bar" in file_1.php and try to get the value in file_2.php it is not there before page reload. Obviously it has to do with the rendering/formatting order. Is there a more or less dirty trick to intrude the session vars into Hanna Code in the first run?
  2. Meanwhile I found a solution. It might be not the most elegant one, but leads straight to the expected result. Just in case someone else is interested: <?php /** * Render a nested list of comments to a page recursively * @param array $page->comments * @param int $maxDepth comment levels, usually the same as set in comments settings * @param array $doneComments, keeping ids of already processed comments * @return string * */ function renderComments($comments, $maxDepth = 0, $doneComments) { $out = ""; global $doneComments; foreach($comments as $comment) : $id = $comment->id; // comment already processed -> next loop if (in_array($id, $doneComments)) continue; // comment never seen before -> fill in array and go ahead $doneComments[] = $id; $out .= "\n<li>"; // add comment content here if($comment->children() && $maxDepth) { $out .= renderComments($comment->children, $maxDepth-1, $doneComments); } $out .= "</li>"; endforeach; if ($out) $out = "\n<ul class='level-".$maxDepth."'>".$out."</ul>\n"; return $out; } global $doneComments; $doneComments = array(); echo renderComments($page->comments, 3, $doneComments); ?> Each comment’s id goes into an array that labels it as 'done'. In the next loop we check the array whether the current comment is already 'done' and continue if so.
  3. Hi there, I’m struggling with a threaded comment system based on this function: <?php function renderComments($comments, $maxDepth = 0) { $out = ""; foreach($comments as $comment) : $out .= "\n<li>"; // add comment content here if($comment->children() && $maxDepth) { $out .= renderComments($comment->children, $maxDepth-1); } $out .= "</li>"; endforeach; if ($out) $out = "\n<ul class='level-".$maxDepth."'>".$out."</ul>\n"; return $out; } ?> Let’s say, there are 9 comments and 3 levels in this order: com-1 ---- com-2 --------- com-4 --------- com-5 --------- com-7 ---- com-3 --------- com-6 --------- com-8 --------- com-9 In this example, the function above returns: com-1 ---- com-2 --------- com-4 --------- com-5 --------- com-7 ---- com-3 --------- com-6 --------- com-8 --------- com-9 com-2 ---- com-4 ---- com-5 ---- com-7 com-3 ---- com-6 ---- com-8 ---- com-9 com-4 com-5 com-6 com-7 com-8 com-9 The problem is obviously caused by some logic issues in the recursion. When I use basically the same function for a page tree, everything works as expected. The comments seem to be structured different, especially their child roles. How can I stop the output after round 1 to get the expected result? Thanks in advance.
  4. Update: The issue was obviously fixed by @ryan and is working fine now. Tested with PW 3.0.168. Thanks a lot!
  5. Another thanks @dragan , Page::loaded was indeed the wrong method. ProcessPageEdit::buildForm delivers the $page object I was looking for – that's great! I have to play around a little with details to find out whether After or Before work better for my needs. Btw: I didn’t want to conceal the big plan, but I first had to check if I get the edit page object done before I could start to concretize a few foggy approaches for getting some rather weird customer wishes done.
  6. Thanks, @dragan, I guessed exactly the same 🙂 Unfortunately that guess didn’t lead me to somewhere useful yet. When I do $wire->addHookAfter('Page::loaded', function($event) { $page = $event->object; if ($page->whatever) { // do something } }); $page contains all pages, not just the one I’m currently editing. Is there any chance to isolate this particular page in an object?
  7. Hi all, when I’m editing a page in the backend, eg. /processwire/page/edit/?id=1032, is there a way to get the currently edited page (here: id=1032) as a page object, let’s call it $pageInEdit? The big plan behind would lead a bit too far, just a simple example what I would like to achieve: if ($pageInEdit->field == 'foo') { // send a message or do something else } Thanks in advance
  8. @MoritzLost This is a very elegant approach indeed! I’ve already built it in and it works flawlessly. I also appreciate it’s temporary nature that allows me to keep everything like it is, and just get rid of the helper field and the hook as soon as the select issue might be fixed someday. So another big thanks for that! (Btw: time comsumption was manageable, 5 minutes or so …)
  9. @Robin S Thank you for the information and opening a new issue. The sort option on the mentioned site is not critical, but as I work with Select Options quite often, I’m looking forward to a fix in the hopefully not too distant future. I agree to your (and @MoritzLosts) suggested Page Reference workaround – it’s one of my favourite field types, but sometimes seems a bit oversized for minor settings.
  10. @louisstephens @MoritzLost Thanks to both of you. I forgot to mention that I tried it with separated values before, unfortunately the same thing happened. In any case the db table field-direction just stores IDs so sort=direction sorts by those numbers. sort=direction.value is leading to the same error as sort_direction.title (1054 Unknown column) and sort=direction->value as well as sort=direction->title do no sort at all. I was hoping it would be just a syntax problem, obviously things are a bit more complicated …
  11. Hi, I would like to sort pages by the title of their Select Options field direction. Its easy to sort them by their option ID but not by their title. The ID’s/titles are: 1=north 2=west 3=south 4=east I would like them sorted alphabetically: east, north, south, west. What I’ve tried so far: $tracks = $pages->find("template=basic, sort=direction); // sorts north, west, south, east following the ID’s $tracks = $pages->find("template=basic, sort=direction->title); // sorts nothing at all $tracks = $pages->find("template=basic, sort=direction.title); // error: field not found If there’s no better way, I could change the select options so that ID’s and titles have the same order. Unfortunately there are quite a few pages that would need to get edited, so I’d like to avoid that. Thanks in advance
  12. Thanks a lot, dragan. You’re right, I should have specified the "where" a bit more – in this case I meant the page itself in edit mode as in your case 2. Anyway, I checked out the runtime markup field and it does exactly what I was looking for with very little effort. Perfect solution!
  13. Hi guys, I’m dealing with a problem that first didn’t even look as one, before I found out that it might not be that easy. I would like to have a link list of external sources referenced by page X. Something similar to the Page field but for external web pages and with different numbers of references. I tried to do it with a repeater field containing a text input and an URL field. That’s nearly all I want, except that I’d like it to be clickable on the admin page like so: <li><a href='URL_1'>TEXT_1</a></li> <li><a href='URL_2'>TEXT_2</a></li> The link list will be used for admin purposes only, as there are several research sources per page, that would be faster accessible than by copying/pasting URLs out of the input fields. So it’s more an admin GUI problem, as it would of course be no big thing to render a link list on the frontend. Any ideas to get that done?
  14. Hi guys, I was working with the Images Extra module for quite a while, and now I’m trying to migrate a bunch of those fields to the new core solution that came with PW 3.0.142. So far, anything is great except one thing I neither like nor understand. All custom fields corresponding with an image are stored in the filedata column like so: {"_field_1_id":"value_1", "_field_2_id":"value_2", etc.} Now some of the values store unicode escapes for diacritical characters like ü, ö, ä, ß (eg. 'K\u00fcche' instead of 'Küche') while other values of the same type are stored unescaped. Unfortunately I cannot detect any system, values from the same fields store identical values sometimes escaped, sometimes unescaped. Although the output works fine in any case, looking at things like 'K\u00fcche' slightly depresses me, so I would prefer to store all values in proper, readable characters. How could I do that?
  15. Thanks a lot, arjen and Robin S. At least my ignorance of the notes in the settings tabs is undoubtedly a bit embarrasing. But good to understand it for now and the future.
  • Create New...