Leaderboard
Popular Content
Showing content with the highest reputation on 09/21/2013 in all areas
-
Hi Guys, I've decided to share my work on a Fieldtype for adding star ratings to page items. I used @apeisa's FieldtypePoll as a starting point. Check out the readme on github for usage: https://github.com/jdart/FieldTypeRate I've got a couple screenshots that should demonstrate the functionality. Feel free to give me any feedback. Regards, Jonathan8 points
-
Hi Guys, I'd like to share a module the development team at metric marketing and I came up with. I have a lot of experience with the Symfony framework, and when working with PW I came to miss some of the practices I grew accustomed to when working with PW. This module is aimed at bridging my previous experience with doing things to PW way. I have a big readme on the github project so be sure to check that out to get all the details: https://github.com/jdart/Spex From the readme "The project makes use of lessphp, less.js, jQuery, modernizr, Minify and the ProcessWire Minify Module." There's an example site in the github repo that illustrates how Spex works: https://github.com/jdart/Spex/tree/master/example-site In short your template file isn't responsible for including the head and foot etc... and instead is injected into a layout. In addition to this is adds some conventions for adding css/less/js to the page so that it can be combined and minified. Have a look through it and let me know if you have any feedback.5 points
-
Hi Emmanuel and welcome to PW. PW does not control the frontend code at all, you have complete flexibility to write the output exactly as you need, including the adding of form labels. As an example, there are different ways to do this, but if you are using PW's built-in method for generating forms, you can do something like: $f->name = "myField"; $form->label = __("Field Title"); Obviously you need to build the other elements of the form, but you get the idea. You can of course use normal HTML: <label for="myField">Field Title</label> The advantage to the first approach is that the label can be made translatable using PW's language support. You can use Bootstrap, or any other framework you wish. Ryan has recently developed a Zurb Foundation profile for PW, but it is not too difficult to use any of the other frameworks. http://modules.processwire.com/modules/foundation-site-profile/ http://processwire.com/talk/topic/2411-bootwire-basic-twitter-bootstrap-profile/ http://processwire.com/talk/topic/3832-release-unsemantic-site-profile/ PW supports multilanguage: http://processwire.com/api/multi-language-support/ You can always access the database directly. It is a standard MySQL database so you can view it easily with something like PHPMyAdmin. You can also of course query it directly using SQL statements, but in most cases using PW's API and selectors is much easier. Hope that helps get you on your way to CMS nirvana3 points
-
Hey guys, another green website from the processwire beginners based near munich. This website is our first REAL PW project - and (for us) one of the biggest sites we‘ve ever built. And actually the first one with a CMS/framework that we did totally on our own. So, don‘t be too negative - but don‘t be too positive either. http://www.roha-gmbh.de There are still many things that are not perfect yet, but since we started to design this website in 2011, it really was time to get it "into the wild" now! Many furniture manufacturers still haven‘t sent their best product images, so that is why there are still some lowres images in there. The project chapter needs some work on the photos as well, but that time will come... The site is not responsive yet, because it wasn‘t our main goal in 2011 - so we only wanted to get it working on tablets and phones, but without any special mobile styles. This will come, but that may take a while. The modules we used: - formbuilder - procache - redirects - versioncontrol - sitemapxml I‘m totally glad I found processwire a few months ago, because at first we planned to get that site done with pure static html. Which would not be TOO nice with about 80 html pages and many, many images (about 400). Finally a few "thank you"s to ryan, soma, diogo (for creating processwire and your help in this lovely forum) and to mademyday (for posting this on twitter, which made me read about processwire). Comments are welcome! Of course!2 points
-
You would need a script for sure for importing data. But you have to divide the task in three: 1. Build the "site theme" in processwire. This is not more than identifying all the different pages on the website, divide their html by templates and replace the dynamic parts. 2. Mirror the website structure in the PW tree. 3. import the previous content to the new site. Your site seems to follow a very simple structure (not too different from the default PW website, so you can take some ideas from there), I would say 5 templates maximum: Home, basic-page, blog, contact, site-map. Header and footer would be the same in all templates, being that home would have a subheader (very easy since that one just follows the header in the markup). basic-template would need only two fields: body and headline and and title (this is for mirroring the website as is, although with processwire you could actually make the content richer by creating more specific templates. But let's stick to mirroring the website for demonstration purpose). The structure could be something like: Home (render "Poland" page) -- Poland (headline: Poland Explorer Travel and Tourist Guide) ---- About Poland Explorer ---- How to use Poland Explorer ---- ... -- Provinces (headline: Provinces of Poland) ---- Poland Explorer Travel and Tourist Guide ---- About Poland Explorer ---- ... -- Geography (headline: Geography of Poland) ---- Map of Poland ---- Mountains of Poland ---- ... -- History (headline: History of Poland) ---- Heads of State of Poland ---- Katyn Forest Massacre ---- ... -- Other Activities ---- Aviation ---- ... -- Blog ---- Article 1 ---- Article 2 ---- ... -- Contact&Search -- Sitemap (hidden from navigation) The basic template would be something like this: <? php include('head.inc'); php include('sidebar.inc'); echo $page->headline; echo $page->body; php include('footer.inc'); Yes, that simple! sidebar.inc would be something like: <div class="column fourcol"> <?php include('search.inc'); <h4><?php echo $page->headline; ?></h4> </div> <div class="widget widget_nav_menu"> <ul id="menu-provinces-of-poland" class="menu"> <?php $children = $page->children->count ? $page->children : $page->siblings; foreach($children as $c) { echo "<li><a href='{$c->url}'>$c->highlight</></li>" } ?> </ul> </div> ...and so on. There are plenty of examples in the default site that would fit very well in practically all problems you would find. The importing part is well covered in Ryan's post that was linked above.2 points
-
Thanks adrian! I actually thought I had fixed that months ago... And I had, but the changes unfortunately never made their way into GitHub until now. Anyways, multi-lingual titles are now fixed. Also, I pushed a little new feature as well: now you're able to choose a role and page permissions are shown for that role for each listed page. Hovering those yes/no texts gives a short explanation (as the titles are just single letters to keep it compact).2 points
-
Just wanted to post it here for others that might look for an example. I'm currently working on importing a Site to PW2.1. Following code I figured is needed to create pages using the Bootstraped API: <?php include(./index.php) // bootstrap PW $p = new Page(); // create new page object $p->template = 'page'; // set template $p->parent = wire('pages')->get('/about/'); // set the parent $p->name = 'mynewpage_url'; // give it a name used in the url for the page $p->title = 'My New Page'; // set page title (not neccessary but recommended) // added by Ryan: save page in preparation for adding files (#1) $p->save(); // populate fields $p->image = 'path/to/image.jpg'; // populate a single image field (#2) $p->images->add('path/to/image1.jpg'); // add multiple to images field $p->save(); // testing echo 'id: '.$p->id.'<br/>'; echo 'path: '.$p->path; Note: in PW 3 with multi-instance support adding new Objects https://processwire.com/blog/posts/processwire-2.6.21-upgrades-comments-more-on-pw-3.x/#more-updates-on-processwire-3.0 [Edit by Ryan #1] Added first $p->save(); [Edit by Ryan #2] Changed $p->image('...') to $p->image = '...';1 point
-
I'm working on a module where I use MarkupCache within the module. Normally you would use MarkupCache in a template, but I fancied putting it in the module as it needs to use some 3rd party classes and it's just a lot of code to dump into a template. What the module does is my own version of pulling and caching X tweets from Twitter. The problem I had was clearing the cache when I'd changed the number of tweets to store in the module's config and saved the config. With help from netcarver it became apparent that you can hook into saveModuleConfigData, but it then took me a while to work out how to hook it. The answer was in InputFieldPageName.module on lines 134-7: static public function getModuleConfigInputfields(array $data) { $modules = wire('modules'); $modules->addHookBefore('saveModuleConfigData', null, 'InputfieldPageName_saveModuleConfigData'); So not in the init() where I'd been trying to put it, but in the getModuleConfigInputfields function instead. Because it's here though, you have to put the function that's called outsite of the class' scope, but that's not an issue really. In that same module you can scroll to the bottom and after the last closing curly-brace is this: function InputfieldPageName_saveModuleConfigData(HookEvent $event) { $arguments = $event->arguments; if($arguments[0] != 'InputfieldPageName') return; $data = $arguments[1]; $name = 'replacements'; if(!is_array($data[$name])) $data[$name] = InputfieldPageName::replacementStringToArray($data[$name]); $arguments[1] = $data; $event->arguments = $arguments; } You can still use the wire class from in there as well, so you can still pretty much do what you like. In my case it was this simple two-liner (setting the cache to 0 seconds effectively wipes it): $cache = wire('modules')->get("MarkupCache"); $cache->get("latest_tweets", 0); Just thought that might be useful to someone else in future So thanks again to netcarver, and also to ryan for having had the need to do this before and making saveModuleConfigData hookable!1 point
-
Keep in mind: If you don't enjoy or don't want to spend time to learn site building and want to focus on content, then I would suggest using some website tool like squarespace etc. or having friend or collegue who does the maintenance work. But if you do want to learn new tech, then we are here to help. PW is great tool to learn site building "the right way"1 point
-
If I understand you correctly, this sounds like a job for Hanna Code: http://mods.pw/4b1 point
-
Greetings, What makes ProcessWire so excellent is the ability to do all kinds of work at the API level, so that you can essentially create a custom admin for your projects. Editing a page is of course a crucial part of any custom admin. NOTES: Of course, you must cutomize this to your project. Also, in my code I am editing the page directly inside the page itself. In other words, you display a page as usual, but inside it you have your edit code, as well as code to save the page after editing. The other option would be to link to another page just for editing. Editing does get rather involved. Below is a technique I've used. I'll break editing down to several steps, then later I'll put it all together as one. Here goes... Step 1: Isolate Who Has Editing Rights You don't want anyone who can view the page editing it! I use code like this to limit editing to people with either an "editor" or "superuser" role. We open it here, and close it later in Step 6: <?php if ($user->isSuperuser() OR $user->hasRole("editor")) { Step 2: Set the $page Variables (Except Title) to Hold Edited Values Take inputs received from a submitted form and use those values to replace current $page values. For this example, I am only using two fields to keep it simple. And they are text fields. We hold off on setting the title, since that needs special handling: <?php if ($input->post->title) { $page->set("first_name", $sanitizer->text($input->post->first_name)); $page->set("last_name", $sanitizer->text($input->post->last_name)); } Step 3: Edit Title Field, but Only if the Title is Unique, Then Save the Page You need something like this so you don't get an error if the title you apply to the edited page collides with the title of an existing page. The code below confirms that the title is unique and allows you to set the title, and only then save the page: $thistitle = $page->title; $matchedtitle = $input->post->title; $checktitles = $pages->find("parent=/[path]/[to]/[parent]/, title=$matchedtitle|$thistitle"); $titlecount = count($checktitles); if($titlecount < 2) { $page->of(false); $page->set("title", $sanitizer->text($input->post->title)); $page->set("name", $sanitizer->text($input->post->title)); $page->save(); Step 4: Refresh URL Think about it... If while editing this page we changed the title, the URL you are on is no longer valid. Here's a simple bit of Javascript to handle this. The code below also closes out the conditional set in Step 3: $refresh=$page->url; ?> <script type="text/javascript"> window.location = '<?php echo $refresh ?>'; </script> <?php } Step 5: Handle the Scenario When the Page Title Collides In Step 3, we edited the page title because it passed the "unique" test. But what if it fails that test? We would move to this section of code, where a message lets the user know there is a problem. A bit of Javascript helps make the warning fade in so it is more noticeable: else { ?> <div class="admin_error_box"> <p>Sorry, there is already a page using this title: <?php echo $input->post->title?>!</p> <p>Please enter a different title in the form.</p> </div> <script> $(function() { $('.admin_error_box').hide().fadeIn(3000); }); </script> <?php } Step 6: The Edit Form We need a form to capture the submission of edits. It would look the same as your page-creation form, but would have to be pre-populated with the current values of the page, which will also change upon submission of the form. The last bit of code closes out the check on user roles set in Step 1: <div class="page_create_form_box"> <p class="form_heading">EDIT THIS PAGE USING THE FORM BELOW</p> <form action="<?php echo $page->url ?>" method="post"> <ul> <li><label class="label_class" for="title">Page Title:</label> <input type="text" class="input_class" name="title" value="<?php echo $page->title ?>"></li> <li><label class="label_class" for="first_name">First Name:</label> <input type="text" class="input_class" name="first_name" value="<?php echo $page->first_name ?>"></li> <li><label class="label_class" for="last_name">Last Name:</label> <input type="text" class="input_class" name="last_name" value="<?php echo $page->last_name ?>"></li> </ul> <button class="admin_submit" type="submit" name="submit">SAVE EDITED PAGE</button> </form> <?php } ?> Step 7: Putting it all Together Now let's put all of this code into one continuous routine. <?php if ($user->isSuperuser() OR $user->hasRole("editor")) { ?> <?php if ($input->post->title) { $page->set("first_name", $sanitizer->text($input->post->first_name)); $page->set("last_name", $sanitizer->text($input->post->last_name)); } $thistitle = $page->title; $matchedtitle = $input->post->title; $checktitles = $pages->find("parent=/[path]/[to]/[parent]/, title=$matchedtitle|$thistitle"); $titlecount = count($checktitles); if($titlecount < 2) { $page->of(false); $page->set("title", $sanitizer->text($input->post->title)); $page->set("name", $sanitizer->text($input->post->title)); $page->save(); $refresh=$page->url; ?> <script type="text/javascript"> window.location = '<?php echo $refresh ?>'; </script> <?php } else { ?> <div class="admin_error_box"> <p>Sorry, there is already a page using this title: <?php echo $input->post->title?>!</p> <p>Please enter a different title in the form.</p> </div> <script> $(function() { $('.admin_error_box').hide().fadeIn(3000); }); </script> <?php } ?> <div class="page_create_form_box"> <p class="form_heading">EDIT THIS PAGE USING THE FORM BELOW</p> <form action="<?php echo $page->url ?>" method="post"> <ul> <li><label class="label_class" for="title">Page Title:</label> <input type="text" class="input_class" name="title" value="<?php echo $page->title ?>"></li> <li><label class="label_class" for="first_name">First Name:</label> <input type="text" class="input_class" name="first_name" value="<?php echo $page->first_name ?>"></li> <li><label class="label_class" for="last_name">Last Name:</label> <input type="text" class="input_class" name="last_name" value="<?php echo $page->last_name ?>"></li> </ul> <button class="admin_submit" type="submit" name="submit">SAVE EDITED PAGE</button> </form> <?php } ?> My apologies for any problems with the formatting of the code above (please use your editor to assure proper tabs). Notes: - If you include checkboxes or other field types in your page, the editing is a bit more involved. - If you have image fields, you would have separate actions connected with those. For more information on handling image fields in custom forms, take a look at this: http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/ That should get you started! Follow up if you have more questions! Thanks, Matthew1 point
-
$config->minify = new FilenameArray(); $config->minify->add("test.js"); $config->minify->add("test2.js");1 point
-
This is the way to create template and fields with API: // new fieldgroup $fg = new Fieldgroup(); $fg->name = 'new-template'; $fg->add($this->fields->get('title')); // needed title field $fg->save(); // new template using the fieldgroup $t = new Template(); $t->name = 'new-template'; $t->fieldgroup = $fg; // add the fieldgroup $t->noChildren = 1; $t->save(); // add one more field, attributes depending on fieldtype $f = new Field(); // create new field object $f->type = $this->modules->get("FieldtypeFloat"); // get a field type $f->name = 'price'; $f->precision = 2; $f->label = 'Price of the product'; $f->save(); // save the field $fg->add($f); // add field to fieldgroup $fg->save(); // save fieldgroup All pretty much standard OO one can figure out looking at core and PW modules. But not someone unexperienced would figure out by themself. I think at some point we need to cover these in a documentation.1 point
-
You can assign fields to templates like this: $template = $templates->get("some_template"); $template->fields->add("newfield"); $template->fields->save(); this code is taken from here http://processwire.c...bles/templates/ So, just make an array with all the templates you want the field to be on, and go for it $ts = array("home", "basic-page", "search"); foreach($ts as $t){ $template = $templates->get($t); $template->fields->add("newfield"); $template->fields->save(); } EDIT: the field will be on the last position of each template1 point
-
Hey neil (are you neil?), I'd say go check out the source of configurable modules. The code for building the configuration options is there - you'd only save the fields into db: // this is a container for fields, basically like a fieldset $fields = new InputfieldWrapper(); // since this is a static function, we can't use $this->modules, so get them from the global wire() function $modules = wire('modules'); // Populate $data with the default config, because if they've never configured this module before, // the $data provided to this function will be empty. Or, if you add new config items in a new version, // $data won't have it until they configure it. Best bet is to merge defaults with custom, where // custom overwrites the defaults (array_merge). $data = array_merge(self::getDefaultData(), $data); // showModal field $field = $modules->get("InputfieldCheckbox"); $field->name = "showModal"; $field->label = "Use modal window"; $field->description = "Whether open pages in modal (overlay) window or goes to traditional administration."; $field->value = 1; // providing a "checked" value for the checkbox is necessary $field->attr('checked', empty($data['showModal']) ? '' : 'checked'); $fields->add($field); return $fields; This is from latest AdminBar by @apeisa. You can see the '$field' part, where the field is built. You probably only run $field->save() at the end instead of current $fields->add() and you have just created field via code Adding fields to the template will be probably close to the ->add() call, and I'm totally not sure about reordering them in the templates via code, you might need to play with this a little.1 point