Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/03/2016 in all areas

  1. You've already understood that $page is always the current page. To output contents of another page, you have to retrieve that page first and store it into a variable. You can do that with $pages->get(). <?php $page1 = $pages->get('/page1/'); /* must be the path to your page from home, e.g. simply '/' if you want to retrieve the home page itself */ ?> <section> <h1><?= $page1->title ?></h1> <p><?= $page1->summary ?> <br> <?= $page1->message ?> </p> </section> As always, there are multiple ways to make things easier and more intuitive in PW, depending on the exact requirement. One important thing to understand about ProcessWire is that you store content in pages but define both structure and output in templates (forgive me if I'm being overly verbose here. I always try to point things out in detail for others stumbling upon a forum page later on with a similar question in mind). In most cases, you'll have multiple pages with the same template, and what additional content you want to show depends on the template. You may have a page 5, page 12 and page 34 that are similar and all need to include content from page 1 - in that case, you can give them all the same template and hard-code page 1 in the template like I did above. Or they all need to include content from another page, but that page varies. Instead of defining a different template for each one, you add a page field to their template definition, choose the page to include in the page editor and, instead of retrieving a page explicitly, you simply use the properties of the page field as it will be a full-fledged page object. <section> <h1><?= $page->yourpagefield->title ?></h1> <p><?= $page->yourpagefield->summary ?> <br> <?= $page->yourpagefield->message ?> </p> </section> You can even go one step further and define your own PHP template for outputting a page's contents in a different context. There's a forum thread with good points and examples illustrating different ways of page and field rendering and the use of wireRenderFile. These open up tons of possibilities to organize your template structure, even allowing you to build flexible widget systems with very little code.
    7 points
  2. Another possible approach would be to add the condition in the head of the calculator template file, include the result template when met and return, otherwise proceed as normal. calculator.php: <?php if($input->get->firstvalue && $input->get->secondvalue ) { include('_result.php'); return; } ?> /* The regular calculator template follows here */ This way, you don't have any "strange magic" that swaps templates and that you'll have to search for when you re-visit the code in three years time
    5 points
  3. For me, it fits perfectly, as I dropped using the SPEX module now, since region() is available. Before that, I used $spex->slot(). Now I'm able to define the main regions in my template prepend file like: // header nav region('headernav', ""); // the body content: region('content', ""); region('sidebar', ""); // all JS codes that should executed at document.ready event, // after jQuery and main.js are loaded: region('JSdocReady', "new myObj().init();\n"); and now, along the way, I can add more code / markup to them. Why I like to use region() over a php var (like $content .= ...), is, that it stands out in the code and indicates (for me) that this is not locally used var, but one of the main buffers that get echoed in the template append file. So, yes, its a personal preference. (That wasn't available before.)
    5 points
  4. and post_max_size should be > than upload_max_filesize add 10% - 20% for other postdata then uploaded files: post_max_size = (max_file_uploads * upload_max_filesize) * 1.15
    4 points
  5. Another little info : memory_limit must be > post_max_size to prevent poorly written scripts for eating up all available memory. And also the LimitRequestBody Apache's directive allows the user to set a limit on the allowed size of an HTTP request message body (set to 0 (illimited) by default).
    3 points
  6. @Ivan Gretsky, I like your point and request for a more detailed explanation to the pro and cons in use cases of API-vars and API-functions! But to be honest, with the region function you overcomplicate things. When you want to use the region function, you will use it all over your tempate files and I'm pretty sure, that you know how it works. (Means, you don't need your IDE telling you about it) But if you really need it, just let out the + sign for a moment, listen to your IDE, and then prepend or append the "+ sign". Ok? @ryan the prepend and append plus-sign is the best of all. The region function is the best, but with the plus-sign functionality it is top of the best!
    3 points
  7. You can try to use the third option in file compiler options of template. https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/#new-compiler-option-for-templates or // FileCompiler=0 https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/#how-to-bypass-the-file-compiler
    3 points
  8. Quick update guys. Frontend module is ready. I have to update the docs first before releasing it though as with anything frontend, there are security implications if the module is not properly set up. Hence, the need to first prep the docs. Will talk more about how it works later but setting up the selects is quite easy. These are defined in a process module in the backend (think Menu Builder) with caching and validation right out of the box. Hope to release next week.
    2 points
  9. As others have said, you have to retrieve the page first. Also, it might have just been a typo here, but don't forget the "$" before your variables!
    2 points
  10. I can't compete with BitPoet's knowledge, but I'm just going to add here that, if you haven't yet already, you'd want to read over the documentation on ProcessWire's selectors. It'll help you understand the different ways you can retrieve Page objects from the system (using $pages->get() or $pages->find()). Selectors: http://processwire.com/api/selectors/ Obviously I'd recommend to read through the entirety of the documentation, but Selectors are probably (in my opinion) the most important thing to understand.
    2 points
  11. Just stepping in to say thanks. Great little module with nice UI for a streamlined content editor workflow.
    2 points
  12. glad you like it. i think ryan likes it too, as the new demo page is also powered by uikit and the roadmap for 2016 (how fast did this year pass?!??) states, that the admin may get powered by uikit as well. really looking forward to that. https://processwire.com/blog/posts/happy-new-year-heres-a-roadmap-for-processwire-in-2016/
    2 points
  13. There could be a region_append, region_prepend or similar functions, or perhaps a third argument append/prepend. I'm fine with the + too, and while I see it's benefits I think I will not use it as it doesn't fit in my workflow.
    2 points
  14. i guess you could also to this: // if submitted $form->addClass('my-form-submitted'); and css like .my-form-submitted input { /* input fields styling for submitted forms */ }
    2 points
  15. @Nico Smit I took a look last night at 3.x with the MVC framework - I ran into a few issues where previously global ProcessWire functions weren't available, such as `wire` and `wireEncodeJSON` in `traits/search.php` and `controllers/javascript.php` (there'll be a couple other files, such as `traits/forms.php`, but I haven't yet scoured all the files), but the issue was remedied by adding the ProcessWire namespace to those files, and using the namespace to access the functions: <?php # traits/search.php use ProcessWire as PW; ... # changed from wire(...) to: PW\wire(...); I didn't have any issues with `Error: Class 'Environment' not found`. I did an install using our generator. UPDATE 06/11/2016: Just released 0.5.9 which adds fixes for the global `wire` calls in the boilerplate: https://github.com/fixate/pw-mvc-boilerplate/releases/tag/0.5.9
    2 points
  16. You may also add a "namespace ProcessWire" into the first line of that template file and set the filecompiler to 0 / none for only that template. But, if you started to work with PW3 now, and will do so in the future, I suggest to always use the namespace ProcessWire in your template files (and sub files) and skip the file compiler completly for all template related stuff! Here, in template section, you have full control, other then in modules section, if you want to use third party modules that are not written as native PW 3 versions.
    2 points
  17. It would be beneficial and helpful to everyone if you could provide whatever solution you came up with. Thanks.
    2 points
  18. good idea with the snippet button! my suggestion would be: case1: code that does NOT get stored anywhere echo 'no comment at first line, no save'; case2: code that goes to history, but NOT to snippets. that would be for some kind of code you need multiple times for a limited period of time (eg developing a module). you could change your code as often as you want, it would only show up ONCE in the history, saying "update module XY 1 -> 2". the list could be limited to around 5 - 10 items. // update module XY 1 -> 2 $m = $modules... $m->upgrade(1,2); case3: when you click on an icon or the like in the list of historical codes, you could make a snippet out of this code. eg "update module XY 1 -> 2 (icon: create permanent snippet)" // my awesome snippet // do stuff for all pages under parent XY foreach($pages->find('parent=XY, ... i think the snippets and codes should always show up only once in the list and hold the last executed code. if you want to apply slight modifications you could just update the comment in the first line (like creating a new branch on github) // my awesome snippet - TEMP CHANGE XYZ // do stuff for all pages under parent XYZ foreach($pages->find('parent=XYZ, ... after the change you could rename the comment and overwrite your old snippet
    2 points
  19. @Juergen - what about installing @Pierre-Luc's AutoDetect language switcher module: http://modules.processwire.com/modules/autodetect-language/ If that is set up to redirect to the /en/ version of the page, then the translated version of the login message etc should be displayed.
    2 points
  20. I recommend using API $variables for most cases, but here are a few instances where you may prefer the function versions: If an API variable is out of scope (like in a function), then you may find the new function versions very useful. If your editing environment provides more benefits to you for using the function versions (like auto-completion and docs) then that's also a compelling reason to use them too. This is something we haven't been able to provide before now. If both of the above apply to you, then also use the functions API where you would have previously used wire(). If neither of the above apply to you, then just use API $variables (fewer characters to type, and no questions about what instance). Basically, use whatever provides the most benefits to your scenario. For all practical purposes, $page and page() are synonymous. I don't see any reason to use $wire in template files–that's really more for core use. The new skyscrapers template files were specifically developed to demonstrate the API variables as functions for that blog post. Basically, I wanted to show you how they work rather than just telling you. So I went out of my way to use them for this particular case. I personally use API variables in my sites, though will be glad to have the convenience of more options when needed. Function alternates to our API variables have been requested multiple times. That's because it's more friendly in how it enables communication between developer and editing environment. I agree that's a good reason to have them. However, you'll likely only want to use them if you find them beneficial in this way. It's completely IDE friendly, and that's actually one of the reasons for this approach versus using user defined $variables for regions. We're just working with strings here. Keep in mind the "+" is only something you add to the region name if you specifically want to prepend or append to an existing value that's already present in there… and most usages probably won't involve that. I'm not sure how to make prepending or appending more convenient than adding a single "+" character to the region name. I'm lazy and don't like to type a lot, so gravitate towards the simplest possible solution. But always open to suggestions.
    2 points
  21. this is another solution i used lately: javascript for handling the clicks: // mobile menu click handler $('#tm-mobile-nav').on('click', 'a,i', function() { // if the link icon was clicked go to url if($(this).is('i')) { location.href = $(this).data('mobile-link'); $(this).removeClass('uk-icon-arrow-right').addClass('uk-icon-spinner uk-icon-spin'); } }); css for handling the visibility: /* mobile menu */ #tm-mobile-nav li .uk-icon-arrow-right { display: none; } #tm-mobile-nav li.uk-parent.uk-open .uk-icon-arrow-right, #tm-mobile-nav li.uk-parent .uk-icon-spinner { display: inline-block; margin-left: 10px; } and php (using custom UIKIT markup): $out .= "<li class=\"{$cls}\"><a href=\"" . ($item->numDropdownItems ? '#' : $item->url) . "\">{$item->title} <i data-mobile-link=\"{$item->url}\" class=\"uk-icon-arrow-right\"></i></a>"; uikit will handle all links with # as collapsible menu items: https://getuikit.com/docs/offcanvas.html live example: https://www.mistelbach-mustangs.at/
    2 points
  22. @Macrura Here's what's above the PW directives in my .htaccess. Notice that I'm pointing explicitly to a 403 html file, right below the 6G directives: ErrorDocument 403 /403.html Start of .htaccess: # 6G FIREWALL/BLACKLIST # @ https://perishablepress.com/6g/ # 6G:[QUERY STRINGS] <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} (eval\() [NC,OR] RewriteCond %{QUERY_STRING} (127\.0\.0\.1) [NC,OR] RewriteCond %{QUERY_STRING} ([a-z0-9]{2000}) [NC,OR] RewriteCond %{QUERY_STRING} (javascript:)(.*)(;) [NC,OR] RewriteCond %{QUERY_STRING} (base64_encode)(.*)(\() [NC,OR] RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC,OR] RewriteCond %{QUERY_STRING} (<|%3C)(.*)script(.*)(>|%3) [NC,OR] RewriteCond %{QUERY_STRING} (\\|\.\.\.|\.\./|~|`|<|>|\|) [NC,OR] RewriteCond %{QUERY_STRING} (boot\.ini|etc/passwd|self/environ) [NC,OR] RewriteCond %{QUERY_STRING} (thumbs?(_editor|open)?|tim(thumb)?)\.php [NC,OR] RewriteCond %{QUERY_STRING} (\'|\")(.*)(drop|insert|md5|select|union) [NC] RewriteRule .* - [F] </IfModule> # 6G:[REQUEST METHOD] <IfModule mod_rewrite.c> RewriteCond %{REQUEST_METHOD} ^(connect|debug|delete|move|put|trace|track) [NC] RewriteRule .* - [F] </IfModule> # 6G:[REFERRERS] <IfModule mod_rewrite.c> RewriteCond %{HTTP_REFERER} ([a-z0-9]{2000}) [NC,OR] RewriteCond %{HTTP_REFERER} (semalt.com|todaperfeita) [NC] RewriteRule .* - [F] </IfModule> # 6G:[REQUEST STRINGS] <IfModule mod_alias.c> RedirectMatch 403 (?i)(wp-admin|wp-content|wp-login) RedirectMatch 403 (?i)([a-z0-9]{2000}) RedirectMatch 403 (?i)(https?|ftp|php):/ RedirectMatch 403 (?i)(base64_encode)(.*)(\() RedirectMatch 403 (?i)(=\\\'|=\\%27|/\\\'/?)\. RedirectMatch 403 (?i)/(\$(\&)?|\*|\"|\.|,|&|&amp;?)/?$ RedirectMatch 403 (?i)(\{0\}|\(/\(|\.\.\.|\+\+\+|\\\"\\\") RedirectMatch 403 (?i)(~|`|<|>|:|;|,|%|\\|\s|\{|\}|\[|\]|\|) RedirectMatch 403 (?i)/(=|\$&|_mm|cgi-|etc/passwd|muieblack) RedirectMatch 403 (?i)(&pws=0|_vti_|\(null\)|\{\$itemURL\}|echo(.*)kae|etc/passwd|eval\(|self/environ) RedirectMatch 403 (?i)\.(aspx?|bash|bak?|cfg|cgi|dll|exe|git|hg|ini|jsp|log|mdb|out|sql|svn|swp|tar|rar|rdf)$ RedirectMatch 403 (?i)/(^$|(wp-)?config|mobiquo|phpinfo|shell|sqlpatch|thumb|thumb_editor|thumbopen|timthumb|webshell)\.php </IfModule> # 6G:[USER AGENTS] <IfModule mod_setenvif.c> SetEnvIfNoCase User-Agent ([a-z0-9]{2000}) bad_bot SetEnvIfNoCase User-Agent (archive.org|binlar|casper|checkpriv|choppy|clshttp|cmsworld|diavol|dotbot|extract|feedfinder|flicky|g00g1e|harvest|heritrix|httrack|kmccrew|loader|miner|nikto|nutch|planetwork|postrank|purebot|pycurl|python|seekerspider|siclab|skygrid|sqlmap|sucker|turnit|vikspider|winhttp|xxxyy|youda|zmeu|zune) bad_bot # Apache < 2.3 <IfModule !mod_authz_core.c> Order Allow,Deny Allow from all Deny from env=bad_bot </IfModule> # Apache >= 2.3 <IfModule mod_authz_core.c> <RequireAll> Require all Granted Require not env bad_bot </RequireAll> </IfModule> </IfModule> ErrorDocument 403 /403.html <FilesMatch "\.(js|css|html|htm|php|svg)$"> SetOutputFilter DEFLATE </FilesMatch> <ifModule mod_headers.c> Header set Connection keep-alive </ifModule> # ---------------------------------------------------------------------- # Expires headers (for better cache control) # ---------------------------------------------------------------------- <IfModule mod_expires.c> ExpiresActive on # Your document html ExpiresByType text/html "access plus 0 seconds" # Data ExpiresByType text/xml "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType application/json "access plus 0 seconds" # Favicon (cannot be renamed) ExpiresByType image/x-icon "access plus 5 days" # Media: images, video, audio ExpiresByType image/gif "access plus 1 week" ExpiresByType image/png "access plus 1 week" ExpiresByType image/jpeg "access plus 1 week" ExpiresByType image/webp "access plus 1 week" ExpiresByType image/svg+xml "access plus 1 week" # HTC files (css3pie) ExpiresByType text/x-component "access plus 1 month" # Webfonts ExpiresByType application/x-font-ttf "access plus 1 month" ExpiresByType font/opentype "access plus 1 month" ExpiresByType application/x-font-woff "access plus 1 month" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" # CSS and JavaScript ExpiresByType text/css "access plus 1 week" ExpiresByType application/x-javascript "access plus 1 week" </IfModule> ################################################################################################# # START PROCESSWIRE HTACCESS DIRECTIVES # @version 3.0 # @indexVersion 300 ################################################################################################# ....
    2 points
  23. PrevNextTabs Module Github: https://github.com/outflux3/PrevNextTabs Processwire helper modules for adding page navigation within the editor. Overview This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.) Usage This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links. Warnings If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits. For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed. http://modules.processwire.com/modules/prev-next-tabs/
    1 point
  24. COMPOSER ELLIOTT CARTER (December 11, 1908 - November 5, 2012) is internationally recognized as one of the most influential American voices in classical music, and a leading figure of modernism in the 20th and 21st centuries. https://www.elliottcarter.com/ This site was launched some months ago, and was one of the larger projects I completed so far. It took about 4 month to build. (PW 2.7.3) This was the first project I used the wireRenderFile() pattern on, and it consequently allowed me to reuse a lot of output code, as well as do a lot of markup/object caching with wirecache. The site uses DataTables for all of the major listing pages, Works, Discography and Events, allowing users to filter and search with no page reload. This probably has the most advanced caching setup that I've done so far, and one example of how it works is on the discography page: https://www.elliottcarter.com/discography/ That page has to hold all 264 albums (json object which is rendered by dataTables), and each album takes a bit of processing to render (formatting of works, artists etc.). The json for each album's list view is wirecached individually and is generated on visits to the individual album pages, so that they never get generated all at once when visiting the discography page. The complete json object containing all of the albums is also wirecached, then the final page is pro-cached. The album covers are lazy loaded so as to not affect page size or load speed. The selects on the left are also all wirecached as page or regular arrays. This results in a 1.6s page load time and a page size of 1.12 MB. Without the data being wirecached the load time is around 9 seconds to generate the page, probably longer if it had to regenerate all 264 albums, but the album info never changes, so they are permanently cached unless someone edits one. Also should note that since there is so much use of wirecache, @Soma's Clear Cache Admin was pretty much indispensable for managing all of the caches. Other features of the site include extensive use of Schema.org microdata, an events submission system, and a lot of custom stuff in the admin for managing the content, such as automated fetching of album covers from Amazon, converting formbuilder submissions into events, a custom admin dashboard etc.. There are probably 60 modules in use overall, but these in particular saved the day: MenuBuilder AdminCustomFiles AdminPageFieldEditLinks All the Selectize modules URL checker PrevNextTabs WireMailMailgun SetupPageName Changelog AdminCustomPages Twitter Feed Social Share Buttons RSS Enhanced Chosen Select Runtime Markup Batch Child Editor Tracy Debugger As well as all of the pro modules (ProFields, FormBuilder, ListerPro, and ProCache). More info, screen shots etc will be gradually posted here...
    1 point
  25. I think you're in the wrong place - this is the support forum for ProcessWire, not Wordpress! ProcessWire also has a hanna code plugin - I think that is your confusion, but since you are here, maybe you should stay
    1 point
  26. Yep, you can do that, just not in init.php. You need to do it in ready.php because the page is not available yet in init.php
    1 point
  27. No apologies necessary; I appreciate even just the initial response! There's no expectation of a response, but thanks again for the reply!
    1 point
  28. Thanks for all the answers guys. I changed the JS structure a bit to solve my problem. There are enough ways around this problem, but I still want to point out that I think that any kind of automation should be fail-safe as possible. A totally generic regex is not slightly fail-safe. It's not even code related, I could have "require(..." as a static text on a page. Don't get me wrong, I don't want to bash PW. As I said, I think there are enough ways to work around this problem. But an automation should be sane or at least point out it's obvious traps and disadvantages in the first place. Anyway, cheers for your help!
    1 point
  29. Just found out that ProcessWire already handles the setWireAndDatabaseStuff in WireDatabasePDO::backups. So, instead of this: $backupPath = $config->paths->assets . 'backups/database/'; $backupMeta = new WireDatabaseBackup($backupPath); $backupMeta->setWire($meta); $backupMeta->setDatabase($meta->database); $backupMeta->setDatabaseConfig($meta->config); $backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']); ...it could be just this: $backupMeta = $meta->database->backups(); $backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']);
    1 point
  30. working on API forms this module comes very very handy...
    1 point
  31. Just to add upon louis' answer: mpdf is shipped as part of the Pages2Pdf (and it's WirePdf) module. It might supply some nice shortcuts if you want to render Page data or plain html markup.
    1 point
  32. Hello @bernhard of course: adding a submission class to the form itself will be the easier way instead of adding it to every field . Maybe to less coffee this morning. Beside this topic: Thanks for pointing me to UIKit (you have mentioned in one of your emails that you use this framework). I have tested it and I find it much better than Bootstrap. Its also better to integrate with the form API of PW.
    1 point
  33. One might want to use regions to make them easier to pass around and not to conflict with existing variables. But anyone coming to project from outside of PW has to read the blog or the code to guess what that + means.
    1 point
  34. Thanks for the hint. I didnt know that there are CSS properties for valid and invalid. Anyway! I have solved it by adding a class after submission with this piece of code: foreach ($form as $field){ $field->attr('class' , $field->attr('class') . ' submitted'); //add class submitted after form submission } So every field will get the additional class "submitted". The code must be placed after $input->post->submit. Now I can style the inputs depending on their state. Thanks
    1 point
  35. The docs for MSN do cover this. If your parent page has a particular template you can use the xtemplates and xitem_tpl options. For more advanced targeting you can use a hook, for example: $nav = $modules->get('MarkupSimpleNavigation'); $nav->addHookAfter('getItemString', function($event) { $page = $event->arguments('page'); if($page->children->count()) { $event->return = "<button class='$page->name'>$page->title</button>"; } });
    1 point
  36. Just looked at this issue recently. This seems to do the job: $this->addHookAfter('FieldtypeRepeater::wakeupValue', function($event) { $field = $event->arguments('field'); // Only for a particular repeater field // Could also use page argument for other tests if($field->name !== 'my_repeater') return; $pa = $event->return; $pa->sort("-created"); // or whatever sort you want $event->return = $pa; });
    1 point
  37. @Juergen This might be interesting: https://developer.mozilla.org/en-US/docs/Web/CSS/:valid and :invalid Or you could add a class like "submitted" to the form after it has been submitted once. Then you would know that the inputs without error are valid.
    1 point
  38. Thanks for all those ideas @bernhard and @szabesz - You can already hide the debug bar by clicking the "x" at the far right of the bar, so I think that covers the "hide once" requirement. As for sticky - you need a way to restore, which is what the toggle button does, so I think I'll go for the toggled off by default on phone sized screens. I like the history idea and I wonder if an additional "Save Snippet" button could complement this such that snippets are automatically saved to history each time that first comment line is changed (maybe the last 5), and saved more permanently to a snippets library if you click the save button? Anyway, these are on my list and hopefully I can get to them shortly. Thanks again for the input!
    1 point
  39. Could be you need to increase post_max_size
    1 point
  40. Sorry for the late answer. I don't exactly know the "internal uses", other than ProDrafts makes use of it. Maybe thats all it is used for, but if not it is best not to mess around with it in my opinion.
    1 point
  41. The compiler, unfortunately, isn't really picky about things. It touches keywords like "require" and "include" inside and outside of the "real" PHP code, including comments. So, the quick solution would be to load hljs the classic way (<script src=...>).
    1 point
  42. It is always important to eat your own dog food. It is interesting how coming to site design with PHPStorm at hands can change the whole API paradigm at once) As now we have at least 3 ways to call an API variable it would be incredibly important to have a detailed explanation about how to take a decision what to choose. Most of us used to use $page, but newcomers starting with demo profile will be using page(), and we are not even touching on wire() and $wire. It seems like @ryan is more into the function interface (you wouldn't be inventing it other way, would you). Please consider making an article about when to choose what, if you got time. I really like the regions functionality, but the + at the beginning and at the end seems magical and probably goes against the initial functional interface intention to have closer IDE integration. I do not think this could be advised by IDE (or am I missing something?) Is there or should there be other more convenient way to append and prepend to regions?
    1 point
  43. I also have a copy of the script that optionally handles deletion of the source variations too. I'll post that when its had some more testing.
    1 point
  44. Hi tom. bad news are here: (files&images are not supported) https://processwire.com/talk/topic/9841-field-dependency-on-image-field/#entry94527 but the good news are there: (go a little indirection) https://processwire.com/talk/topic/9841-field-dependency-on-image-field/#entry94530 hope this helps regads mr-fan
    1 point
  45. I was struggling a bit getting all subfields of a field if type is unknown. I made a small function for use in templates which returns an array() of all properties of (maybe any?) pagefieldvalue. If there is something similar in core (which I couldn't find) please let me know. Tested it with Fiedtype Options, Page, ProfieldsTable. Feel free to use it. /** * ProcessWire UsefulSnippets * * How to get all properties, subfields of any field if you don't know the type only if value is set * @return array */ function getProperties($fieldvalue) { // multiple value field if ($fieldvalue instanceof WireArray) { $result = array(); foreach ($fieldvalue as $subfieldvalue) { $result[] = getProperties($subfieldvalue); } return $result; // single value field with subfields } else if ($fieldvalue instanceof WireData) return get_object_vars($fieldvalue->getIterator()); // single value field else return $fieldvalue; } // Example var_dump(getProperties($page->myfield));
    1 point
  46. Didn't know about wireRenderFile(...) Thank you LostKobrakai. For the situation at hand, Soma's tip seems more natural. But the wireRenderFile may be very useful in other ways... Thank you both.
    1 point
  47. Ah! That looks much better... complete code below /** * site/config.php */ $config->appendTemplateFile = '_layout.php'; /** * site/templates/home.php */ $title = $page->title; $shop = $pages->get('/shops/mr-big'); $mainContent = $shop->render('partials/shop-intro.php', ['appendFile'=>null]); /** * site/templates/partials/shop-intro.php */ <div class="shop-intro"> <h2><?= $page->title ?></h2> <?php foreach( $page->shop_photos AS $photo ) : ?> <img src="<?= $photo->url ?>" /><br/> <?php endforeach; ?> <div class="shop-desc"> <?= html_entity_decode($page->shop_description) ?> </div> </div> /** * site/templates/_layout.php */ <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?= $title; ?></title> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body> <h1><?= $title; ?></h1> <div class="container"> <?= $mainContent ?> </div> </body> </html> I like it like this... If anyone has a better way, feel free to jump in.
    1 point
  48. I you're searching for a more flexible way to include snippets / not always whole sites, maybe this is a more appropriate function: // returns the output of snippets/contactform.php // the second argument is optional and will be passed to // the called file as multiple variables with the name of the key // also all api varables are available by default wireRenderFile("snippets/contactform", array("stuff" => $something ));
    1 point
  49. There's many different options, so there's also a option to overwrite it in the render options. $p->render("template", array("prependFile" => ""));
    1 point
  50. @Yannick Are you sure? $p = new Password(); $hash = $p->randomBase64String(); // 100=length of string? too long for the forum ;-) echo $hash; // output example: 3JrVekq0ZRPVJadm8i601Z1 What do you mean with 'activate via GET' just transmit or more? All the best from Paris
    1 point
×
×
  • Create New...