Jump to content

Soma

Moderators
  • Posts

    6,798
  • Joined

  • Last visited

  • Days Won

    158

Everything posted by Soma

  1. Well no reason behind I think, all core Process modules execute() are hookable whether useful or not. I this case you could replace the add form with your own, what else But to be honest it would be better if buildForm() would be hookable, but nobody needed it so far so it's not. The thing is the execute() returns the form rendered already so you can't manipulate it using OOP.
  2. Soma

    Image tags

    Every find will return a PageArray already, no need to explode to get the page id as array you already got them... My guess is that most people try to echo $p, and see that there's something like "1002|1230|2130" ... but that's not what's really behind $p and seems a common misunderstanding of non-coders. It's the magic toString() method of PageArray that returns the id's in that way. See https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/PageArray.php#L407. So what you trying to do an extra step to explode something that PW implodes. This stringification is handy if you want to use the result $p in a selector. "id!=$p" will result in "id!=1002|1230|2130". But in your case you already have an PageArray and simply can loop the pages inside $p. $p = $pages->find("images.tags~=$tag") foreach($p as $onepage) { echo $onepage->title; }
  3. It's the famous "how to do this" question.
  4. Maybe this is also interesting https://github.com/mexitek/phpColors
  5. Ryan the localUrl doesnt work if theres 404 thrown for a url. When you call a url that doesnt exist it will stay at that url and renders the 404 page. There it fails because something with the page names language module doesnt have a language set or something I cant remember. I think its maybe also only if not default language or the user has alternative language set. Try that changing user language and see.
  6. If you leave outer tpl empty you should still specify the "||" .. 'outer_tpl' => '||'
  7. This method is different from what we normally use for select options. As you can guess from the responses, we use page fields to build selects and the options are actual pages. http://processwire.com/videos/page-fieldtype/ This allows for much more flexible and dynamic building as the options are coming from pages. The select field you're using is completely different as you have options hardcoded into the field, you could just hardcode the labels in your template too. You know which key has which value. Or to make things simpler you could use the inputfield interface of the select field to get the options.. $options = $fields->selectfieldname->getInputfield($page)->getOptions(); echo $options[$page->selectfieldname];
  8. Is it possible you don't use a page field, but the custom select field like http://modules.processwire.com/modules/fieldtype-select/?
  9. Just wanted to let you all know, I updated the module to 1.1.9 , with another new hook method to manipulate or add your very special case classes that will get added to list_tpl's "%s". To use this, here a little example to make it clearer. I want to add a class to my page with id 1001. Ok here we go. $nav = $modules->get("MarkupSimpleNavigation"); function hookGetListClass(HookEvent $event){ $child = $event->arguments('page'); // current rendered page item (in naviation) $class = $event->arguments('class'); // the class string, may be empty or filled if($child->id == 1001){ // add your checks, use API or whatever... daytime... $event->return .= " yourclass"; // add your class names } } $nav->addHookAfter('getListClass', null, 'hookGetListClass'); echo $nav->render(); Added this to readme
  10. In PW 2.3 all jQuery traversing methods are available. So not yet in the cheatsheet is things like prevAll(selector) or nextAll(selector), nextUntil(selector) ... For what you ask I think this is what you need: $found = $page->siblings("template=mytemplate,body*=your text")->first(); if($found->id) { echo $found->body; } Nothing to explain really, except that sibling() is like find() and returns an PageArray of pages even if only one found. So to get the first from the array you add ->first. This will return on the one page and you can make sure it has one found with if($found->id){... Edit: ok maybe another one on a sidenote, when working with $page->siblings(), it will also return all including the page you're calling this from. So you could add a selector "id!=$page->id" to exclude it.
  11. It was updated 4 hours ago... Yes there's a readme with examples...
  12. Have you got the latest version? https://github.com/ryancramerdesign/MarkupTwitterFeed Ryan has done some updates today/yesterday
  13. Little detail. Instead of $p->setOutputFormatting(false); you can also use $p->of(false);
  14. I still have no idea what you want to target and how you imagine doing it... So I can't help. I know what a child of a parent is, but it's not something I can get a hand on in a navigation, it's nothing specific or I just don't get it. Maybe this is something you can use: "list_field_class" => {template} p_{id} or "list_field_class" => p_{name}
  15. I have trouble understanding what you want and why? A child of a parent?
  16. I understand your view. From your first post it's not clear at all, what form... what hook.. are you talking about? You can't assume everybody knows what tools and code you're using, not everybody uses FormBuilder, not everybody uses PW fields for forms. See? Adrian already spent his time and answered with what most would think from your question... after all it wasn't what you looked for. Of course FormBuilder is using InputfieldSelect, and is a general field. So setting a value to the field applies generally, assuming it's single select (multiple select would be different story again). Now here you're somewhat in the context of FormBuilder and you need a special hook in a special place to interact with the form, that is special to FormBuilder. Further, now that you have it working with FormBuilder how about sharing your solution?
  17. This should be in the FormBuilder support forum. We can't know you use FormBuilder... Maybe share you're code with us so we can see what you got? Have you tried something that doesn't work? Without testing or knowing, if you have the form object inside the hook function you should be able to $form->get("fieldname")->value = "subject1";
  18. I don't think categories is the way to go here. 1. Nested Structure This is a good example where the date structure could be used to create the articles. Then you would a) have the urls already and b) an easy way to create lists and such. Additionally add a date field to the article template so you can choose the date and use that for additional searching. /dagboek/ /2008/ /januari/ // or use "01" as name whatever you like /article14012008/ /article15012008/ /februari/ /article01022008/ /2009/ /januari/ Then loop the years and months in a simple nested php script using API. You don't need to check if there's a year or month with articles if you create months manually. $years = $pages->get("dageboek")->children(); $out = ''; foreach($years as $year) { $out .= "<ul>"; $out .= "<li><a href='$year->url'>$year->title</a>"; if($year->numChildren) { $out .= "<ul>"; foreach($year->children() as $month) { $out .= "<li><a href='$month->url'>$month->title</a></li>"; } $out .= "</ul>"; } $out .= "</li>"; $out .= "</ul>"; } echo $out; Then on the years or months template file, you simply render out their children in any fashion you like and may add pagination using the built in Pager module. You'll have urls like /dagboek/2008/01/page1, dagboek/2008/01/page2 2. Flat The other route would be to use a flat structure and add articles to the /dagboek/ parent. Then add a date field to the article template you can define the day this article is for. Then use a script that checks for articles (oldest, newest) and generate a menu with virtual urls for each year and month that has articles. The URL then can be resolved using urlSegments to show a list of articles for the selected month. You'd have to enable url segments on the dagboek template to make this work. This is a script I created for generating a year month nested menu only for the ones that articles are found. $datefield = "mydate"; $template = "article"; $url = $pages->get("/dagboek/")->url; $newest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=-$datefield, limit=1")->first->getUnformatted($datefield)); $oldest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=$datefield, limit=1")->first->getUnformatted($datefield)); $out = ''; for($y = $oldest; $y <= $newest; $y++){ $out .= "<li>"; $out .= "<a href='#'>$y</a>"; $month_out = ''; for($m = 1; $m <= 12; $m++){ $month_start = strtotime("$y-$m-1"); $month_end = strtotime("$y-$m-1 +1 month"); $selector = "template=$template, $datefield>=$month_start, $datefield<$month_end"; if($pages->count($selector)) { // use count instead of find for fast query $month_out .= "<li><a href='{$url}$y/$m/1'>$m</a></li>"; } } if(strlen($month_out)) $out .= "<ul>$month_out</ul>"; $out .= "</li>"; } echo "<ul class='menu'>$out</ul>"; Then, on the dagboek template something like: if($input->urlSegment1 && $input->urlSegment2) { $year = (int) $input->urlSegment1; // 2008 $month = (int) $input->urlSegment2; // 02 $start = strtotime("$year-$month-01"); $end = strtotime("$year-$month-01 +1 month"); // find the articles for within that current month $articles = $pages->get("/dagboek/")->find("template=article, date>=$start, date<$end, sort=-date"); foreach($articles as $article) { echo "<h2>$article->title</h2>"; echo $article->body; } } Just rough examples.
  19. $thumburl = $image->width > $image->height ? $image->size(450,0)->url : $image->size(0,320); echo "<img src='$thumburl'/>";
  20. I guess you are talking about template output only? You'd then have to build some additional logik and check which side is larger and resize that. You can get the size by $image->height and width.
  21. Huh? Do you mean the "parent_class" ? https://github.com/somatonic/MarkupSimpleNavigation/blob/master/MarkupSimpleNavigation.module#L26
×
×
  • Create New...