-
Posts
4,956 -
Joined
-
Last visited
-
Days Won
100
Everything posted by LostKobrakai
-
if else failing (but working in HannaCode)
LostKobrakai replied to Peter Knight's topic in General Support
You're mostly missing the curly braces for the foreach, which is only allowed if only a single following statement is supposed to be foreached. $news = $pages->find("template=news-item, sort=-post-date"); foreach ($news as $newsItem){ $title = $newsItem->body ? "<a href='{$newsItem->url}'>{$newsItem->title}</a>" : $newsItem->title; $icon = "<i class='uk-icon-newspaper-o uk-icon-justify'></i>"; echo "<div class='uk-width-1-1 news-headline-wrap'>{$icon}{$title}</div>"; } -
$user objects are not always (never??) in output formatting ON mode like all other pages are – even on the frontend. And as long as output formatting is off these field settings are ignored and you'll always get a list of images. So in the case of working with the user object it's wise to force a specific formatting: $user->getFormatted('image_field'); // Returns regarding to the fields setting $user->getUnformatted('image_field'); // Returns always a list (does not break when field settings would change)
-
Just use $user->getUnformatted('userimage') and you'll get a Pageimages object no matter what. It's less error prone especially as the output-formatting on user objects is sometimes a bit iffy about when it's on or not.
-
That's expected to error there. The interesting part is where the exception did come from earlier in the call stack. And maybe look at that textformatter. There's some code calling last() on an image, while the object is probably supposed to be a list of images.
-
For basic selectors this would have probably been enough. Though I'm not sure if it covers all edge-cases correctly. $isShown = $page->is($field->showIf);
- 5 replies
-
- 4
-
- Inputfield
- conditional logic
-
(and 3 more)
Tagged with:
-
Do you do anything in hooks related to images (maybe on the user template)? Also Tracy will probably give you a stack trace, which might be helpful to debug this further.
-
The frontend-editing feature is mostly meant for editors. While you could use it for other users as well it might not offer the best options in terms of user-experience.
-
It a really strange move of a hoster to enable caching without explicit user-consent. Without knowledge of the applications running on their systems this is more or less expected to cause serious troubles. Also – this might be nitpicking – but it's not a bug in pw if the server's caching mechanism is returning outdated content.
-
I just wanted to share this library here: http://barbajs.org/ It's a pjax implementations specifically for handling page transitions without full page-reload as simple as possible. It's super lightweight and can literally be installed by pulling the library in, adding two classes to your pages and a single line to initialize the whole thing. I've just added this to my personal site (https://kobrakai.de/) and beyond some js refactorings – mostly so that animations are not only triggered on page loads – it was a very smooth experience to add. Also I've probably only scratched the surface on this simple site. The docs look like this could handle even more complex setups if needed.
- 3 replies
-
- 17
-
add 'modified date' in the export field page
LostKobrakai replied to antpre's topic in Wishlist & Roadmap
This might be possible if the modified date on fields would actually be saved by processwire, which it isn't. I've been wondering about this, too. I'm not sure why this is the case. Seems odd at least. -
modifying $config property (e.g. siteSettings) from ready.php
LostKobrakai replied to Macrura's topic in General Support
@Macrura May I suggest using WireData instead of StdClass. This makes code more resilient to missing properties and prevents lot's of isset() nonsense. $a = new \stdClass(); if($a->test) echo $a->test; // Will generate a PHP Notice "Undefined Property: …" $a = new WireData(); if($a->test) echo $a->test; // Does nothing; $a->test === null -
This would cache only the xml for an hour. <?php $goodreads_api = 'xxxxxx'; foreach($page->children as $bundle) : foreach($bundle->goodreads as $goodreads) : $xml_string = $cache->get($goodreads->isbn, 3600, function() use($goodreads_api, $goodreads) { return file_get_contents('https://www.goodreads.com/search/index.xml?key='.$goodreads_api.'&q='.$goodreads->isbn); }); $book_xml = new SimpleXMLElement($xml_string); foreach ($book_xml->search->results->work as $book) : // content goes here endforeach; endforeach; endforeach;
-
Can you explain what you're trying to do? It seems quite odd for a textformatter to be autoloaded.
-
Inputfield dependencies are as the name suggests part of the inputfields, which are rendered as part of the backend forms. It's not directly bound to the fields in any way. Also while those dependencies are evaluated by php once when saving a form it's otherwise a pure javascript based evaluation. You could try to create the backend form manually and let it evaluate the show-if statements, but that's really not how it's meant to be used.
- 5 replies
-
- Inputfield
- conditional logic
-
(and 3 more)
Tagged with:
-
Method(s) to cycle through foreach/compare values of Children
LostKobrakai replied to creativejay's topic in API & Templates
Read this example fully and you'll understand your issue: http://php.net/manual/en/functions.anonymous.php#example-200 -
Link to specific page in archive with pagination
LostKobrakai replied to verdeandrea's topic in General Support
I'm not sure if there's really a better way to do this, without potential for breakage. $pageNum = 1; $limit = 20; $start = $pageNum - 1 * $limit; $base = "template=news, id=$mySearchedPage->id"; while($pages->count($base . ", start=$start")){ $count = $pages->count($base . ", limit=$limit, start=$start"); if($count) break; $pageNum++; $start = $pageNum - 1 * $limit; } -
if($input->pageNum == 1){ $featured = $page->get('template=blog-article, sort=-article_date'); } $rest = $page->find("template=blog-article, limit=10, sort=-article_date, id!=$featured"); // Create any pagination markup here! if($input->pageNum == 1){ $rest->prepend($featured); } // Render items
-
Memory exhausted, because of exception error
LostKobrakai replied to suntrop's topic in General Support
How about printing just the exception's message instead if the whole object? -
Method(s) to cycle through foreach/compare values of Children
LostKobrakai replied to creativejay's topic in API & Templates
Essentially we're doing this in the array_reduce() [Page, Page, Page] => [ 'key' => [Page, Page], 'key2' => [Page] ] So just count how many items the resulting array has. If 1 show only the key, otherwise do the array_map(). I think the argument about more structure (compared to loops) is far more valid than the "shorter is better" one. I'm using Laravel's collection package via https://github.com/tightenco/collect with some additional hooked in functions and especially such transformation tasks are so much clearer to create as well as to read. -
Method(s) to cycle through foreach/compare values of Children
LostKobrakai replied to creativejay's topic in API & Templates
Not bad at all, you just need to use $child->field->title (or ->value, if you're using those). It's just that the key needs to be some sting or int. And replace line 9 with this. Missed the PA part of the variable. Also the second argument of the implode call is supposed to be the "title" of your children or you'll just end up with something like this: green (green, green, green), blue (blue, blue) return "$price_emea_eur (" . $childrenPA->implode(", ", "title") . ")"; -
Method WireArray::each() doesn't work as expected
LostKobrakai replied to kixe's topic in General Support
$featured->each(function($item){ $item->set('foo', 'bar'); }); //or $preparePost = function($item){ $item->set('foo', 'bar'); }; $featured->each($preparePost); A plain string is not a valid callable, therefore your version isn't supposed to work. -
Method(s) to cycle through foreach/compare values of Children
LostKobrakai replied to creativejay's topic in API & Templates
Make sure $child->prod_fiber_type is a string and not an object (page field?). -
There is nothing like that in ProcessWire's backend. Almost everything is stored in pages and if you need such a section just create a template and a (hidden) page (e.g. named settings) and use it. Another option is to extend the $config variable (site/config.php) with custom properties. There's also a module, which allows you to change those properties in the backend, but it's not as flexible in terms of UI as a page with custom fields would be.
-
PW 3.0.20: Comprehensive recap of ProcessWire 3.x so far!
LostKobrakai replied to ryan's topic in News & Announcements
If you haven't changed the sessionName it'll always default to 'wire'.