BeardedCanadian Posted September 22, 2013 Share Posted September 22, 2013 Hi all, I've been using EE 1.x/2.x for my personal website for a long time and I'm looking at switching to PW for a variety of reasons. I have a sand-boxed version installed and I have been working through a few of the tutorials. At this point I'm investigating how difficult it will be to re-impliment what I have. I am good enough with perl/SQL that migrating my previous content isn't too much of a concern. One of the things I cannot quite get my head around is how best to reimpliment a 'thought' and 'links' section of my current site. Thoughts are basically, tweet-like ramblings that I write while links are a simple url (which are associated with a datestamp, but nothing else). In the basic and news article tutorials, an author is always presented with a two-step entry process where the 'Title' and 'Name' slug for each page is first entered and a 2nd step where the content is entered. This works fine for blog posts/articles as these warrant a slug url. However, for 'thoughts', 'links' and 'quotes' I would really rather not have a 'Title' or a 'Name' field at all as these are intended to be quick entries. From a little digging, I gather that each page in PW is expected to have a 'Title' as it is marked as a global field and this is used to fill the 'Name' slug which maps to the page ID. Is there an easy way around this? In terms of fields, I want: Thoughts: - Simple line of text, limited to 512 characters - datestamp entry Quotes: - Simple textarea - Quoted author - Quoted date - datestamp of entry Links: - url - Simple line of text, limited to 128 characters, describing the url/link. - datestamp of entry Thanks for the help. Link to comment Share on other sites More sharing options...
daniel.s Posted September 22, 2013 Share Posted September 22, 2013 One thing you could do is to only do 3 pages: -Thoughts -Quotes -Links Inside these pages you could have a repeater field with the needed fields. Then it's just a matter of hooking up the fields where you need them. $quotes = $pages->get("/quotes/"); foreach($quotes->quotes as $quote) echo "<h3>{$quote->textarea}</h3><small>{$quote->author}</small>"; Im completely new and more of a designer than a programmer so don't know if the code works or if it's a solution for your needs but it's what i would have done. Link to comment Share on other sites More sharing options...
diogo Posted September 22, 2013 Share Posted September 22, 2013 @daniel.s, this is not a good case to use repeaters as the number can grow to the point of not being practical at all. Pages is the way to go. @BeardedCanadian (great name ) the way around the two step page creation is to create a new system for making these new pages. You can easily create new pages with the API http://processwire.com/talk/topic/352-creating-pages-via-api/. So, the only thing you need is to a new page where you put a form with the needed fields for your thoughts/quotes/links and use the API to create the pages instantly. If you want these pages in the admin, have a look at my Admin Custom Pages module http://modules.processwire.com/modules/process-admin-custom-pages/. edit: and welcome to the forums both of you! 1 Link to comment Share on other sites More sharing options...
BeardedCanadian Posted September 23, 2013 Author Share Posted September 23, 2013 Thanks for the input. @diogo, any chance you can walk me through a basic example of how to set this up or point me to a thread that describes how to use the API to accomplish something similar? After installing your custom admin page module, I'm greeted by a note stating, "This page has no Process assigned." Link to comment Share on other sites More sharing options...
diogo Posted September 24, 2013 Share Posted September 24, 2013 (edited) Here is an example for how to create the "thoughts pages". Let's say we have all our thoughts as child pages of a "thoughts" page, and that they will have a template name "thought". home -- one page -- another page -- thoughts ---- my first thought (template: "thought") ---- one more thought ---- ... --admin Create a "new thoughts" custom page in the admin (follow the instructions in the module), and paste this to it's template: <?php if($input->post->thought) { $thought = new Page(); $thought->parent = $pages->get("/thoughts/"); $thought->template = "thought"; $thought->name = time(); // page name can be a timestamp, this will make it unique $thought->title = substr($input->post->thought, 0, 30); // let's make the title match the first 30 characters of the thought $thought->body = $input->post->thought; $thought->save(); // confirmation message with link to edit the new thought echo "<p>A new thought was created. Edit it <a href='{$config->urls->admin}page/edit/?id={$tweet->id}'>here</a>.<br>Create a new one?"; }?> <h2>Write a new thought</h2> <form action="" method="post"> <textarea name="thought" rows="4" cols="50"></textarea><br> <input type="submit" value="Send"> </form> After installing your custom admin page module, I'm greeted by a note stating, "This page has no Process assigned." What version of PW are you using? Edit: thanks for the edit Pete, I forgot that detail Edited September 24, 2013 by diogo Changed "tweet" to "thought" in the code just in case there is any confusion 2 Link to comment Share on other sites More sharing options...
diogo Posted September 24, 2013 Share Posted September 24, 2013 I don't want to complicate things, so until the above is working and understood just ignore this post. If you want the fields to match the theme of the admin, you can use the built in methods to create them. Let's adapt Soma's instructions from here http://processwire.com/talk/topic/2089-create-simple-forms-using-api/ to our example above: <?php if($input->post->submit) { $thought = new Page(); $thought->parent = $pages->get("/thoughts/"); $thought->template = "thought"; $thought->name = time(); // page name can be a timestamp, this will make it unique $thought->title = substr($input->post->thought, 0, 30); // let's make the title match the first 30 characters of the thought $thought->body = $input->post->thought; $thought->save(); // confirmation message with link to edit the new thought echo "<p>A new thought was created. Edit it <a href='{$config->urls->admin}page/edit/?id={$tweet->id}'>here</a>.<br>Create a new one?"; } //create a new form wrapper $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'new-thought'); //create a textarea input $field = $modules->get("InputfieldTextarea"); $field->label = "Thought"; $field->attr('id+name','thought'); $field->required = 0; $form->append($field); // append the field to the form //the submit button $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Submit"); $submit->attr("id+name","submit"); $form->append($submit); //render the form echo $form->render(); ?> 3 Link to comment Share on other sites More sharing options...
BeardedCanadian Posted September 24, 2013 Author Share Posted September 24, 2013 Thanks so much for the help. I'm trying this on a new copy of ProcessWire 2.3.4 which I downloaded yesterday. I'm using these instructions for adding the admin page: Create a new template with a file (name it whatever you wish) In the advanced settings insert "admin" as the Alternate Template Filename Create a new page under "Admin" and give it the newly created template Doesn't exist In the template file you can use PW variables as in any normal template (yes, pretend you didn't change the file in the settings) Still seeing the same message, "This page has no Process assigned." At the risk of being verbose: 1) Create a new file /site/templates/thought.php with this code: <?php if($input->post->thought) { $thought = new Page(); $thought->parent = $pages->get("/thoughts/"); $thought->template = "thought"; $thought->name = time(); // page name can be a timestamp, this will make it unique $thought->title = substr($input->post->thought, 0, 30); // let's make the title match the first 30 characters of the thought $thought->body = $input->post->thought; $thought->save(); // confirmation message with link to edit the new thought echo "<p>A new thought was created. Edit it <a href='{$config->urls->admin}page/edit/?id={$tweet->id}'>here</a>.<br>Create a new one?"; }?> <h2>Write a new thought</h2> <form action="" method="post"> <textarea name="thought" rows="4" cols="50"></textarea><br> <input type="submit" value="Send"> </form> 1b) Create a new template using this file 2) In the template settings I added the 'body' field to the pre-existing 'title' field. 2b) In the advanced template settings enter 'admin' as the Alternate Template Filename. 3) I create a new page under "Admin" in the tree titled 'New Thought' and assigned the 'thought' template I just created. 4) I now see the 'New Thought' listed on the right in the topnav navigation menu, but when I click on it I see, 'This page has no Process assigned'. Link to comment Share on other sites More sharing options...
diogo Posted September 24, 2013 Share Posted September 24, 2013 Can you check if the admin.php file in the templates folder was changed during the installation? if so, it should have these lines: // line added for the Custom Admin Pages Module if($page->template->id !== 2) $page->process = "ProcessAdminCustomPages"; If it doesn't, please replace it by the one on github or add these lines yourself just before the require() https://github.com/ocorreiododiogo/pw-admin-custom-pages/blob/master/admin.php Link to comment Share on other sites More sharing options...
BeardedCanadian Posted September 24, 2013 Author Share Posted September 24, 2013 @diogo, that was it. Seems what I pulled down online from the dev branch is missing that line. Thank you very much for the example above Link to comment Share on other sites More sharing options...
diogo Posted September 25, 2013 Share Posted September 25, 2013 That line is not from the PW core, but specific to the module. The module adds it on the installation procedure, but for some reason it didn't happen with you. Link to comment Share on other sites More sharing options...
BeardedCanadian Posted September 25, 2013 Author Share Posted September 25, 2013 I don't want to complicate things, so until the above is working and understood just ignore this post. If you want the fields to match the theme of the admin, you can use the built in methods to create them. Let's adapt Soma's instructions from here http://processwire.com/talk/topic/2089-create-simple-forms-using-api/ to our example above: <?php if($input->post->submit) { $thought = new Page(); $thought->parent = $pages->get("/thoughts/"); $thought->template = "thought"; $thought->name = time(); // page name can be a timestamp, this will make it unique $thought->title = substr($input->post->thought, 0, 30); // let's make the title match the first 30 characters of the thought $thought->body = $input->post->thought; $thought->save(); // confirmation message with link to edit the new thought echo "<p>A new thought was created. Edit it <a href='{$config->urls->admin}page/edit/?id={$tweet->id}'>here</a>.<br>Create a new one?"; } //create a new form wrapper $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'new-thought'); //create a textarea input $field = $modules->get("InputfieldTextarea"); $field->label = "Thought"; $field->attr('id+name','thought'); $field->required = 0; $form->append($field); // append the field to the form //the submit button $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Submit"); $submit->attr("id+name","submit"); $form->append($submit); //render the form echo $form->render(); ?> One small issue with the above is again the reference to $tweet->id rather than $thought->id. Otherwise, it's perfect. Exactly what I needed to get started. Link to comment Share on other sites More sharing options...
diogo Posted September 25, 2013 Share Posted September 25, 2013 I changed that immediately after posting. You are too fast for me Link to comment Share on other sites More sharing options...
Pete Posted September 26, 2013 Share Posted September 26, 2013 Sorry, I probably caused that slight code issue when I changed diogo's code Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now