Leaderboard
Popular Content
Showing content with the highest reputation on 07/18/2015 in all areas
-
I'm using almost the same setup, but my "t" function handles context too. The good thing is that _strings.php can be copied to your next projects too. function t($text, $context = 'General', $textdomain = '/site/templates/_strings.php') { return _x($text, $context, $textdomain); } _strings.php: // Search _x('Search site', 'Search'); _x('No matches', 'Search'); // Forms _x('From', 'Forms'); _x('From email', 'Forms'); _x('To', 'Forms'); ...2 points
-
I use a similar solution to a _strings.php file, and include it from my _init.php file (prependTemplateFile), so that it's available to all templates. But I bundle all the translated values into a new function (which I'll call _t(), but you could name it whatever you want). So you can call upon that _t() function anywhere that you'd call a __() function. For instance, in your /site/templates/_strings.php file... function _t($label) { static $labels = null; if($labels === null) $labels = array( 'Yes' => __('Yes'), 'No' => __('No'), 'Maybe' => __('Maybe'), 'And so on...' => __('And so on...') ); return isset($labels[$label]) ? $labels[$label] : $label; } From there, you can replace any __('label') call with _t('label'). In this manner, you only need to translate your _strings.php file, and all the other template files can use the translated labels. For the cases where you need to translate text that only exists in a particular file, then you'd continue to use the __() function as usual.2 points
-
Ok, there is a new version with a new config setting: Automatic Email Send. This is checked by default, but if you uncheck this, then when creating new users the Send Email checkbox will be unchecked by default, so you will need to manually check each time to want to email a new user upon creation. This setting also works with users added via the API. If unchecked, they won't be sent an email, so you will need to use: $newuser->sendEmail = true; to have the email sent. Hope that meets your needs and others also find it useful!2 points
-
Hi, I'm toying with the idea of having a central place in PW's translation system for phrases and strings that are frequently used throughout several template files. The way I understand PWs translation system after reading the docs (http://processwire.com/api/multi-language-support/code-i18n/) is that everytime a __('translate-me') is used in a different .php file, the system will pull that 'translate-me' in a context of the .php file where it is used - so basically all translatable strings of _one_ file at a time are manageable via the (very cool) translation tool in PW's admin interface. So if for example I were to use __('Daytime phone number') in, lets say, the home.php as well as in the login.php and maybe a profile.php, I'd need to translate this three times, right? - A solution given in the docs is using the gettext context, and have this pointing to the first template file where the string was used first, so I only need to translate that template's strings and the other two will "see" their translation threre. So in my fabricated example: //home.php: __('Daytime phone number'); //login.php: __('Daytime phone number','/site/templates/home.php'); //profile.php: __('Daytime phone number','/site/templates/home.php'); So I only need to look for the translations of /site/templates/home.php in the translation tool and the other occurances of that string will be taken care for. This now brings me to the idea of creating a php file in, say, "/site/language/strings.php". So what I can now do (but what feels kind of hacky to me…?), I use all the frequently used strings of my several template files in this "strings.php" file, wrapped in their language functions like __('translate me'). in _init.php or maybe in config.php I store this file's path for the context: $i18lctx = '/site/templates/language/strings.php'; And now I can use the transalatable strings in several template/php files like this // in home.php, in archive.php etc __('Hello pilgrim',$i18lctx); In PWs admin interface I'll have all the strings in one place: the strings.php (?textdomain=site--templates--language--strings-php). Is this the right way to go about it or am I overlooking a basic fact (maybe like, dude, this is what the language packs are for)? Cheers, Tom1 point
-
AvbFastCache Module Github repoModule Authorİskender TOTOĞLUBig Thanks to phpFastCache authorsphpfastcacheUsage Almost Like original phpfastcache library : I made some modification on original phpfastcache library for use it with ProcessWire. On my side i tested files and sqlite its look working well. You can set default settings from module setting panel or you can use it like original library with custom settings for each call, from module setting panel you can set storage type, cache path, security key, fallback and also you can delete cached data from module settings panel. Modified set function, working like core $cache->get function this function will check a cached data exist ? if not save cache data and return cached data back. Here is some example usages : // Load Module $AvbFastCache = $modules->AvbFastCache; // Set cache settings from module $_c = phpFastCache($AvbFastCache->storage, $AvbFastCache->getConfig(), $AvbFastCache->expire); $output = $_c->set("cacheKeyword", function($page)) { $output = '<h1>{$page->title}</h1>'; $output .= "<div class='body'>{$page->body}</div>"; return $output; }); //=> OR // Do MemCache $_c2 = phpFastCache("memcached"); // Write to Cache Save API Calls and Return Cache Data echo $_c2->set("identity_keyword", function()) { $results = cURL->get("http://www.youtube.com/api/json/url/keyword/page"); $output = ""; foreach($results as $video) { $output .= $vieo->title; // Output Your Contents HERE } return $output; }, 3600*24); // This will check id=1 or parent_id=1 and will return last modified page UNIX_TIMESTAMP as result echo $AvbFastCache->getLastModified(1); // This will check id=1 or parent_id=1 and template=basic-page and will return last modified page UNIX_TIMESTAMP as result echo $AvbFastCache->getLastModified(1, 'basic-page'); // What can you do with last modified dates ? Let me show you an example // Think you are in news page, $page->id is news page id we are using $user->language->id because if we have multi language website // Here getLastModified() function will get last modified date for us, if news page or children pages have any update new cache data will be created automatically // Like this you can set expire time 0 unlimited from module panel ! // Think we are in "new-list" template and listing children pages $keyword = "newsPage" . $page->id . $user->language->id . $AvbFastCache->getLastModified($page->id, 'news-single'); // Load library with your settings $_c3 = phpFastCache($AvbFastCache->storage, $AvbFastCache->getConfig(), $AvbFastCache->expire); // Write to Cache and Display Result echo $_c3->set($keyword, function($page)) { $output = ""; foreach($page->children as $p) $output .= "<h2>{$p->title}</h2>"; return $output; }); You can check phpfastcache usage from phpfastcache wiki or phpfastcache offical website Note : I didn't tested this module with older ProcessWire versions, tested with 2.6.1 or newer versions. Module not have core dependency, it could work also older versions but need to check for be sure !1 point
-
So this is basically a recreation of a menu tutorial from W3Bits, tweaked to include the Advanced checkbox hack. Demo. Even the Advanced hack itself was tweaked: apparently this bit is causing issues with Safari, so I removed it: @-webkit-keyframes bugfix { from {padding:0;} to {padding:0;} }I found this particular configuration to work quite nicely. A previous menu I tried had a problem with the menu items staying expanded between media query breakpoints, when resizing the browser. Below is the CSS for the menu. You will notice that it is mobile-first: /* Menu from http://w3bits.com/css-responsive-nav-menu/ */ /* Note: the tutorial code is slightly different from the demo code */ .cf:after { /* micro clearfix */ content: ""; display: table; clear: both; } body { -webkit-animation: bugfix infinite 1s; } #mainMenu { margin-bottom: 2em; } #mainMenu ul { margin: 0; padding: 0; } #mainMenu .main-menu { display: none; } #tm:checked + .main-menu { display: block; } #mainMenu input[type="checkbox"], #mainMenu ul span.drop-icon { display: none; } #mainMenu li, #toggle-menu, #mainMenu .sub-menu { border-style: solid; border-color: rgba(0, 0, 0, .05); } #mainMenu li, #toggle-menu { border-width: 0 0 1px; } #mainMenu .sub-menu { background-color: #444; border-width: 1px 1px 0; margin: 0 1em; } #mainMenu .sub-menu li:last-child { border-width: 0; } #mainMenu li, #toggle-menu, #mainMenu a { position: relative; display: block; color: white; text-shadow: 1px 1px 0 rgba(0, 0, 0, .125); } #mainMenu, #toggle-menu { background-color: #09c; } #toggle-menu, #mainMenu a { padding: 1em 1.5em; } #mainMenu a { transition: all .125s ease-in-out; -webkit-transition: all .125s ease-in-out; } #mainMenu a:hover { background-color: white; color: #09c; } #mainMenu .sub-menu { display: none; } #mainMenu input[type="checkbox"]:checked + .sub-menu { display: block; } #mainMenu .sub-menu a:hover { color: #444; } #toggle-menu .drop-icon, #mainMenu li label.drop-icon { position: absolute; right: 0; top: 0; } #mainMenu label.drop-icon, #toggle-menu span.drop-icon { padding: 1em; font-size: 1em; text-align: center; background-color: rgba(0, 0, 0, .125); text-shadow: 0 0 0 transparent; color: rgba(255, 255, 255, .75); } label { cursor: pointer; user-select: none; } @media only screen and (max-width: 64em) and (min-width: 52.01em) { #mainMenu li { width: 33.333%; } #mainMenu .sub-menu li { width: auto; } } @media only screen and (min-width: 52em) { #mainMenu .main-menu { display: block; } #toggle-menu, #mainMenu label.drop-icon { display: none; } #mainMenu ul span.drop-icon { display: inline-block; } #mainMenu li { float: left; border-width: 0 1px 0 0; } #mainMenu .sub-menu li { float: none; } #mainMenu .sub-menu { border-width: 0; margin: 0; position: absolute; top: 100%; left: 0; width: 12em; z-index: 3000; } #mainMenu .sub-menu, #mainMenu input[type="checkbox"]:checked + .sub-menu { display: none; } #mainMenu .sub-menu li { border-width: 0 0 1px; } #mainMenu .sub-menu .sub-menu { top: 0; left: 100%; } #mainMenu li:hover > input[type="checkbox"] + .sub-menu { display: block; } }Below is the markup outputted using mindplay.dk's method. I found it impossible to output with MarkupSimpleNavigation or MenuBuilder. The homepage is added as the first top-level item. Notice the onclicks that make it work on iOS < 6.0. The clearfix class cf for the top ul is important. Otherwise the element will have no height (got bitten by this..). <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <ul class='main-menu cf'> <?php /** * Recursive traverse and visit every child in a sub-tree of Pages. * * @param Page $parent root Page from which to traverse * @param callable $enter function to call upon visiting a child Page * @param callable|null $exit function to call after visiting a child Page (and all of it's children) * * From mindplay.dk */ echo '<li><a href="' . $pages->get(1)->url . '">Home</a></li>'; function visit(Page $parent, $enter, $exit=null) { foreach ($parent->children() as $child) { call_user_func($enter, $child); if ($child->numChildren > 0) { visit($child, $enter, $exit); } if ($exit) { call_user_func($exit, $child); } } } visit( $pages->get(1) , function(Page $page) { echo '<li><a href="' . $page->url . '">' . $page->title; if ($page->numChildren > 0) { echo '<span class="drop-icon">▼</span> <label title="Toggle Drop-down" class="drop-icon" for="' . $page->name . '" onclick>▼</label> </a> <input type="checkbox" id="' . $page->name . '"><ul class="sub-menu">'; } else { echo '</a>'; } } , function(Page $page) { if ($page->numChildren > 0) { echo '</ul>'; } echo '</li>'; } ); ?> </ul> </nav>Edit: fixed the end part, thanks er314.1 point
-
This is intentional - if you want the automatically generated password to be used, make sure the password field is not populated. Not surprising - EmailNewUser is not autoload outside of the admin interface - see the instructions for using via the API where it mentions that you need to manually load it first. You could either change: "autoload": "template=admin", in the EmailNewUser.info.json to autoload : true or you would need to hack the FrontendUser module so that it loads this module with: wire('modules')->get("EmailNewUser"); // call the module since it is not autoload on the front end Perhaps you could request for pwFoo to add a check if this module is installed and if so, load it - others might find that useful too.1 point
-
The second seems fine to me, but you can use a simpler syntax (from 2.5.27): $featuredIDs = $pages->get('template=home')->featured_items->id(); http://processwire.com/blog/posts/processwire-core-updates-2.5.27/ Then <?php if (in_array($project->id,$featuredIDs)) : ?> featured<?php endif; ?>1 point
-
You simply create a new template with a multilanguage text field for each expression you want to translate. the name of the fields and labels can be in english, but not necessarily the words that you will output, they would be just informative. Then you fill the fields with all the languages. To output them in other templates, you would do this: // top of the file $translations = $pages->get('/translations/'); // and when needed echo $translations->more_articles; // inside functions echo wire('pages')->get('/translations/')->more_articles;1 point
-
1 point
-
A client recently asked me to make a simple utility that they could use to upload files for public downloads. One of the requirements, for some reason or the other, was clean URIs. Thought it best to do it with PW. Too much of a mission anywhere else, really. Called it Dispo, which comes from Content-Disposition. Sharing in case anyone else may find it useful. This is generally for use on a subdomain - client wants it installed at files.example.com. In config.php, there are two options to set: one for the domain of the main website (Dispo will redirect there when the home page or 404 is hit), and the other for the name the company or, whatever. Best to set these as they default to localhost and ABC & Co., respectively. Create files using the downloader template, specifying a title for the file (this, along with the company name as set in config.php, will be used for the downloaded file name). When the entry (Page) is requested, its file will be downloaded. To view the file instead (if the browser is capable of it), add ?view to the URL. Download below: site-dispo.zip1 point
-
I rebuilt my brothers website from it's WordPress theme/plugin into a ProcessWire designed theme. Mostly because it was build poorly, half the things didn't work and it kept getting attacked through 3rd party plugins, and not knowing much about WordPress other that omg I hate it - decided to look else where! Turned out nice I thought, easily modifiable pages/projects with tagging showcase etc, and using FormBuilder with bootstrap theme for contact form, also ProCache. Will look to try use ProcessWire for further projects, very nice to use as a dev. Cheers John1 point
-
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];1 point