-
Posts
695 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Jan Romero
-
So with your current structure, Folder1 appears under two separate urls. Once under root, and once under /folder1/. To do this in ProcessWire, you can keep the page structure the same way you have shown, with Folder1, Folder2 and Folder3 as children of the frontpage. They are still “neighbors”, or siblings as PW calls them (you can get a page’s siblings by calling $page->siblings()). Since you don’t want to have a dedicated frontpage, you would create a special template for the frontpage and either redirect it to /folder1/, or render Folder1 right there: <?php echo $page->child->render(); //child gets the first child. //this is the entire template. The redirect would work like so: <?php $session->redirect($page->child); //if you put any code here, it will //not be executed. The first option would be more like what you have now, where the frontpage simply mirrors its first child. You can use the same template for other “category” pages, where you don’t need an overview page, but want to go directly to the first item. For completeness’ sake, this would be the full page tree (just add Home at the top): HomeFolder1Page1 Page2 Page3 Folder2Page1 Page2 Page3 Folder3Page1 Page2 Page3 When you think about it, ProcessWire’s approach makes the most sense anyway. Url paths describe a tree, so it’s only natural that there must be a root page.
-
Yeah, that’s true. It works in Ryan’s example at the beginning of the thread because he calls isLoggedin() before overwriting the $user variable with a normal string (strings in php are indeed different from objects). So, confusingly, in that example $user refers to different things at separate times. He should probably edit the post for posterity.
-
That’s how callbacks work, but I believe LostKobrakai can’t use a standard callback, because his requests will be asynchronous. So the callback would get executed as soon as all requests have been made, but it won’t wait for the actual responses. For that he’ll have to use events. So either pool the events of the request objects and fire your own event when all are done, or have a single function handling all requests and executing the callback upon completion. @diogo hehe, I’m glad you got that reference %) @Mike Anthony that’s brilliant! I’ll have to save that link
-
Fun fact about SVGs: Internet Explorer will not scale <img> SVGs properly if they don’t have the viewBox attribute. I’m not sure if it was Inkscape or the optimizer I used, but my SVGs were missing this, and I had to edit it in for IE: width="1024" height="512" viewBox="0 0 1024 512" Without viewBox, the image would remain 1024x512 in IE, but it won’t scale it down and clip it to the <img> tag’s dimensions instead.
-
Feel like you left out the most interesting parts there It sounds like you’re not using jQuery, but if you did, Ajax requests would return Deferred objects that expose done events. You could then use $.when to bind these Deferreds together into a single Deferred that fires such an event once for the entire queue, once all “inner” Deferreds have finished. I recently had to wrap my head around this. Voodoo is an apt description. I think in vanilla JS (I hope this is not the name of some JS library ) you would create an XMLHttpRequest object for each request, whose onreadystatechange events you handle in one function. There you could naively count the successes in a global variable and do your thing once you have all of them. So it kinda depends on what the requests look like and what events you can subscribe to. The requests should run in parallel if you simply send() them one after the other, i. e. the program will not wait for the server response until it executes the next request.
-
I love all of those, but I can’t help but notice how the dignified feel of Eat-Drink-Royal is undermined by the neglected typography. Consider installing SuperSmartypants if you have no control over the texts. Here’s a comparison of the original and two versions with curly quotes and hairspaces: Gotta love that her name is Quayle. It’s far too rare that typefaces get to show off a capital Q, arguably one of the most beautiful characters in any font.
-
The log will be in /site/assets/logs/errors.txt, or in the setup tab in the admin on newer dev-branch installations.
- 6 replies
-
- WireUpload
- FieldTypeFile
-
(and 5 more)
Tagged with:
-
Page Field => direct children of template page
Jan Romero replied to berechar's topic in General Support
What input type are you using? PageListSelect won’t allow custom selectors or custom PHP code. The Autocomplete input type doesn’t support custom code either. If you put return $page->children; as the custom php, it should totally work. -
I updated my post above. Apparently you need a closing php tag at the top, so it doesn’t expect php code. Disclaimer: I have only tested this with a PW and module version from about a year ago.
-
You need to echo the html markup within your outer php tags as strings. Or you can probably just get rid of the outer php tags. <?php echo '<div class="row fullWidth img">'; echo ' <img src="' . $config->urls->templates . 'img/header.jpg" alt="header-picture">'; echo '</div>'; ?> <!-- OR simply: --> ?> //just a closing tag here <div class="row fullWidth img"> <img src="<?php echo $config->urls->templates; ?>img/header.jpg" alt="header-picture"> </div>
-
Sure it’s possible. I’d love to see a more page-field-like PageTable, actually. Here is a (really, seriously) half-assed module that lets you add a page to a PageTable field. Be aware, when you remove your page from the field, it will trash the entire page just like the standard PageTable does. Do NOT use this anywhere but in a testing environment. It also has a hard coded template that you shoult probably change to whatever your PageTable accepts. $this->addHookAfter('InputfieldPageTable::render', $this, 'PageTableRender'); public function PageTableRender($event) { $pageTable = $event->object; $out = "<select name='{$pageTable->name}_addcustom'>"; $pages = $this->pages->find('template=PAGETABLETEMPLATE'); //change this foreach ($pages as $p) { $out .= "<option value='{$p->id}'>{$p->title}</option>"; } $out .= '</select>'; $out .= "<script> $(document).ready(function(){ $('select[name=\"{$pageTable->name}_addcustom\"]').change(addPage); function addPage() { var input = $('input[name=\"{$pageTable->name}\"]'); var container = input.siblings('.InputfieldPageTableContainer'); var dataurl = container.attr('data-url'); var pageid = $('select[name=\"{$pageTable->name}_addcustom\"]').val(); var ajaxURL = dataurl + '&InputfieldPageTableAdd=' + pageid; $.get(ajaxURL, function(data){ container.html(data); container.effect('highlight', 1000); }); alert('wtf did you do'); } }); </script>"; $event->return .= $out; } As you can see, the heavy lifting in the PageTable field is done via Ajax. Maybe it’s a starting point. I really need to go to bed
-
The same disclaimer applies to me, obviously, but you may also want to hook into execute() in ProcessLogin, or, if you’re using the dev version, create your own alternative ProcessLogin. It’s used as an example on the blog.
-
Best practice for backend set up this type of home page
Jan Romero replied to Alfred's topic in Getting Started
This is a great feature you can use to achieve what you want. It basically allows you to generate multiple versions of markup for the same template. There are of course more ways of doing something like this, but render options and partial template files will take you very far, with very clean code. -
selectable pages defined dynamically for Page field in repeater
Jan Romero replied to valan's topic in General Support
When you put a page field inside a repeater, the $page variable that field gets is the page you’re editing. Not the repeater page the field actually belongs to. Put another way, the $page variable will be the same as $repeateritem->getForPage(). What you want, however, is $repeateritem itself. Honestly, I doubt this is possible out of the box. Like you said, if you used “real” pages in a PageTable field, you would edit those pages in a modal window. I. e. the $page variable supplied to the page field’s custom select code would be the current PageTable item. I don’t want to be the guy who misses the point and answers “why don’t you just do something else”, but PageTables are so much cooler than repeaters anyway. Any specific problems that stop you from using those? -
What Ryan described earlier in this thread sounds like exactly what you want? You get a text input where you can just write whatever (thus “free” tagging). That way you don’t need to create pages, but your tags are of course more prone to typos and you have to use urlSegments or GET parameters to show matching pages.
-
How could I assign specific admin page for user role?
Jan Romero replied to adrianmak's topic in General Support
If you have created your own ProcessModule for this, you can add the “permission” property to its module info. Only users with the set permission will load the module. The admin page will be hidden for everyone else. You can also set up your module so that it creates the permission on installation, and automatically removes it when it is uninstalled. -
AJAX and JSONP to do cross-domain calls with ProcessWire?
Jan Romero replied to leoric's topic in General Support
$config->ajax uses $_SERVER['HTTP_X_REQUESTED_WITH'], which isn’t sent with JSONP requests. You can just check for $input->get->callback on the server side to determine if it’s a JSONP request. -
Need help getting URL of a child page for use in it's parent.
Jan Romero replied to MikeB's topic in General Support
Yes, that should be fine. Even if $infoBox had multiple children, this should work and give you the first child. Perhaps the problem lies somewhere in the structure of your function. Would you mind posting the complete function? Is there anything else you do with the $child variable? By the way, the links on your site seem to work right now? -
Seems like the translation JSON is corrupted. Under Languages->Français, can you click on the json file you’re trying to use and verify that the first two properties, file and textdomain are present and correct? It should look like this: {"file":"site\/templates\/theCoolestTemplate.php","textdomain":"site--templates--thecoolesttemplate-php","translations":[…]}
-
Need a little help showing if > children in my menu.
Jan Romero replied to OrganizedFellow's topic in Dev Talk
I’m not exactly sure if that’s what you want, but if you just want to generate a bunch of nested <ul>s, you should recursively travel around the page tree. Something like: function siteMap(Page $root) { $out = "<li>{$root->title}"; if ($root->hasChildren) { $out .= '<ul>'; foreach($root->children() as $child) { $out .= siteMap($child); } $out .= '</ul>'; } $out .= '</li>'; return $out; } Uuuuh… at least I think that should work. Untested It should give you the complete branch starting at whatever you plug into $root. edit: Actually. Something is bound to be wrong with this. And you need to supply the outer <ul> yourself. edit: Tested it. Fixed it because it was stupid. -
Ah. You’re overriding ProcessWire’s $user variable here: $user = $sanitizer->username($input->post->user); Now $user is just some string the visitor entered, and no longer the special user object. Just use a different variable like $username or something. The same thing applies for other API variables like $page, $pages, $session, etc. as well, of course.
-
Indeed. Without really looking into it, the Javascript must depend on the position of the buttons. Try this to insert the buttons inside .InputfieldPageTableContainer: public function PageTableRender($event) { $return = $event->return; $from = strpos($return, "<div class='InputfieldPageTableButtons"); $to = strpos($return, "</button></span></div>", $from); $buttons = substr($return, $from, $to-$from) . "</button></span></div>"; $insertAt = strpos($return, "<table class='AdminDataTable AdminDataList'>"); $event->return = substr_replace($return, $buttons, $insertAt, 0); } Instead of this hackish string trickery, perhaps a better way to clone/move the buttons would be to use Javascript in the first place. I’m not sure how to best pull that off. Just append a script tag to $event->return?
-
There is probably a more robust way to do this, but, uh, I tried $this->addHookAfter('InputfieldPageTable::render', $this, 'PageTableRender'); public function PageTableRender($event) { $return = $event->return; $from = strrpos($return, "<div class='InputfieldPageTableButtons"); $to = strrpos($return, "</button></span></div>", $from); $buttons = substr($return, $from, $to-$from) . "</button></span></div>"; $event->return = $buttons . $event->return; } The Inputfield’s original render method puts the button html in the variable $btn, but I suppose there’s no way to just access that one. Another way to duplicate the button elements would be to just copy the code that generates them.