Jump to content

diogo

Moderators
  • Posts

    4,296
  • Joined

  • Last visited

  • Days Won

    79

Everything posted by diogo

  1. It makes more sense to keep the select tags outside the function, so you can control the attributes new code goes like this: function newLinesToOptions($field){ $options = ""; foreach(explode("\n", $field) as $line){ $line = trim($line); $lowerLine = strtolower($line); $options .= "\t<option value='$lowerLine'>$line</option>\n"; } return $options; }?> <select name="name"> <?php echo newLinesToOptions($page->yourField); ?> </select> edit: No, this is only a normal function. If you have to use it more then once, put the function on an include file and call it with this part of the code: <select name="name"> <?php echo newLinesToOptions($page->yourField); ?> </select>
  2. Again late I buit a function for the newlines solution: function newlinesToOption($field){ $select = "<select>"; foreach(explode("\n", $field) as $line){ $line = trim($line); $lowerLine = strtolower($line); $select .= "<option value='$lowerLine'>$line</option>"; } $select .= "</select>"; return $select; } echo newlinesToOption($page->yourField);
  3. You're welcome! And by the way, I also came from Symphony and I think you will like to work with PW because they share a lot of good things.
  4. I built a function that does exactly what you asked for, it recognizes the format {image_1}, {image_2}, {image_22}, etc: function imageTags($p, $field){ $string = $p->$field; preg_match_all("/{image_[0-9]*}/", $string, $array); foreach($array[0] as $match){ $number = preg_replace("/[^0-9]/", '', $match); $index = $number-1; $image = $p->images->eq($index); $image = "<img src='$image->url' alt='$image->description'>"; $string = str_replace($match, $image, $string); } return $string; } echo imageTags($page,'body'); // first parameter is the page object, second parameter is the field name. // you can also do this: echo imageTags($pages->get(123),'summary') edit: did some cleaning on the code. if you want another format for tags, {img:22} for instance, just change the regex on the 3rd line from "/{image_[0-9]*}/" to "/{img:[0-9]*}/".
  5. Great job Pete! There is a problem with the footer on my Chrome (both dev and stable) and Epiphany (also WebKit). In Firefox is fine edit: now the background is dark, and the footer is ok (footer is not ok)... did you change something?
  6. When I want a max-size i use images like this: if($image->width > 500) $image = $image->width(500); echo "<img src='$image->url' alt='$image->description'>"; and on the css: img { max-width:500px; }
  7. Also, notice that on my code I use multiple classes like class= 'testimonial_box even last' instead of class= 'testimonial_box_even' This should make it easier to style all boxes, and then target these new classes for smaller changes
  8. That's correct, i changed those later, and maybe you copied them before...
  9. you missed the closing brace for the foreach()
  10. You can also leave the parent template without a file to throw a 404 when the page is accessed.
  11. I would do it maybe like this: foreach ($testimonial as $item) { echo "<div class='testimonial_box"; if($testimonial->getItemKey($item) % 2) { echo " even"; } else { echo " odd"; }; if($item == $testimonial->first()) { echo " first"; }; if($item == $testimonial->last()) { echo " last"; }; echo "'>"; echo $item->body; echo "<p>$item->title</p>; echo "</div><!-- /.testimonial_box -->"; } edit: oh, late again... corrected some quote marks
  12. if($item == $testimonial->first()) and if($item == $testimonial->last())
  13. I tested the suggestion of Netcarver and it works. On your code, it would look like this: if( 0 == $testimonial->getItemKey($item) % 2) @Netcarver, getItemKey() is on the cheatsheet. Make sure you have the "advanced" checkbox checked
  14. In native PHP you can do as Soma said before. But I agree that it would be nice to have this built in the API. Let's wait that Ryan comes back to see what he will say about this
  15. I also have this problem with my users. I think I would prefer that TinyMce would make a break on return and a paragraph on double return
  16. % is the modulus operator. you can see if a number is even, by checking that it's modulus is zero http://newsourcemedi...d-even-numbers/ and you can also check if a number is odd simply like I did above if( $count % 2 ) because zero is false
  17. i wonder if this works... if($p->index % 2) //class odd Edit: so many answers while i was writing this Edit: It doesn't work of course, the code above is trying to find the field named index, and not the index of the page inside an array.
  18. You're welcome! I had the same problem recently
  19. Ryan already answered to this on another thread. Here it is: http://processwire.c...r-json-support/ (last answer)
  20. When pressing the links you get a clean URL? If not I would bet you still have to check the "allow page numbers" on the template like Ryan suggested above.
  21. At some point we will have a library of reusable snippets on the website (something like this http://symphony-cms.com/download/xslt-utilities/). I think these kind of things are even better as snippets/functions than as modules, but ya, would also be a nice module
  22. I think the correct way of using repeaters, is using them, only after deciding that we really can't achieve what we want by the traditional ways. In some situations the pagefield, for instance, will do the same work effectively and even in a more elegant way. I love that we have the repeaters, but i agree we should use them consciously.
  23. i worked on it more than i thought i would, but it was fun and i learned with it glad it helped!
  24. Another edit deserves a new post... I noticed that the previous approach didn't work in some situations where last row wouldn't have any page to populate it (on the first screenshot there is an example with 7 rows and 23 pages). I'm not very good at maths, but I thought that, knowing the mod we could distribute the pages in another way. So, here is the new code with the changes commented: $rows = 7; $totalCount = count($jurisdictionsPageChildren); $rowCount = ceil($totalCount / $rows); $mod = $totalCount % $rows; // this will tell us how many rows will have more pages than the others $firstInRow = 0; $i = 1; while ($i <= $rows){ $mainContent .= "<div class='columns six"; if($i == 1) $mainContent .= " alpha"; if($i == $rows) $mainContent .= " omega"; $mainContent .= "'>"; if($i <= $mod){ // do this when we want one more page on the row $sliced = $jurisdictionsPageChildren->slice($firstInRow, $rowCount); $firstInRow += $rowCount; }else{ // do this when we want one less page on the row $sliced = $jurisdictionsPageChildren->slice($firstInRow, $rowCount-1); $firstInRow += $rowCount-1; } foreach($sliced as $p){ $mainContent .= "<h2><a$class href='{$p->url}' title='{$p->title}'>{$p->title}</a></h2>"; } $mainContent .= "</div>"; $i++; } and on the other screenshots, the working version
  25. Ryan is on vacations, maybe he will answer only in one week...
×
×
  • Create New...