Jump to content

kathep

Members
  • Posts

    133
  • Joined

  • Last visited

Community Answers

  1. kathep's post in Adding image to template via code was marked as the answer   
    UPDATE: Just got it to work using:
    $remind = "<img src='http://kathep.com/site/templates/img/remind.png'>"; $content = $remind;  I discovered my FTP client (Transmit) was not updating my experiments due to a weird later timestamp on the remote copy of the file.
    There's nothing like posting to the forum to make things seem obvious that seemed unsolvable before posting.
    Hopefully documenting this simple noob error will help someone else 
  2. kathep's post in Troubleshooting 'Page Field Select Creator': find hidden template and assign it to new pages was marked as the answer   
    RESOLVED
    @Adrian, your reply prompted me to check the parent template. When I originally created the page tree in Page Field Select Creator, I typed 'basic-page' into the template field. 
    What I did not expect is that instead of using the existing basic-page template, Page Field Select Creator created a duplicate basic-page template. I didn't eve know it was possible to have two, identically named templates. Anyway, it is. And the parent basic-page template Page Field Select Creator made had the wrong child template assigned to it (which occurred when I created another page tree using Page Field Select Creator, and selected basic-page as parent, and another template as child).
    Have you ever had this issue of Page Field Select Creator duplicating existing templates? Perhaps it should be noted in the instructions.
  3. kathep's post in How to call only one instance of each entry a relational data field was marked as the answer   
    RESOLVED
    Here is the code I used to fix the duplicate problem. It is mostly @horst's code suggestion from above, with something added (from this stackoverflow post) and something taken away.
    // beginning of new design category code if($design_technique instanceof PageArray) { // create array for collecting output $outItems = array(); foreach($design_technique as $test_skill) { // array collecting categories $alreadyFoundCategories = array(); foreach($test_skill->design_skill_category as $example) { // add it to the list $alreadyFoundCategories["{$example->title}"] = $example->title; // collect for output $outItems[] = $example->title; } } // create the output $import_skill .= implode(" / ", $outItems); $import_skill_clean .= implode(' / ',array_unique(explode(' / ', $import_skill))); } //end of new design category code I didn't know about array_unique or implode then explode tricks until this afternoon. Another lesson in php from processwire implementation. 
    I am cobbling together code from various sources until it works, without really understanding _how_ it works yet. Please forgive ugly syntax and nonsense in my code, and feel free to offer improvements.
  4. kathep's post in CSS file reload lagging in PW was marked as the answer   
    OMG, mind blown! I love this idea.
    Mind blow again!! This is so awesome. I am off to change my prefs...
  5. kathep's post in Best way to display relational data from another page? was marked as the answer   
    Ah, I see  , thank you for the further explanation.
    Here is my write-up of steps for displaying relational data for absolute beginners, based on what the steps I have taken to fix my problem. Please chip in with corrections if any of you know a better way!
    Displaying Relational Data from another page, using fieldtype Page and Input Field Type Single page.
    Original problem:
      Steps to fix:
    Change field course_name_from_list to Single page (choose option: Single page (Page) or empty page (NullPage) when none selected).
      Change $sidebar code from this: $course_w_heading = "<h4>Course: " $page->course_name_from_list . "</h4>"; $sidebar = $course_w_heading; // I made an array and added it to $sidebar because I had extra arrays to add, which I have left out here for the sake of keeping the examples simple. to this:
    // array 1: calls the Page field $course = $page->course_name_from_list; // array 2: includes fields from $course and formatting I want outputted on page $course_w_heading = "<h4>Course: " . $course->course_number . "<br>" . $course->title . "</h4>"; // call sidebar as blank - I'm not sure why this is necessary $sidebar = ''; // if the Page field has a selection, output if($course instanceof Page) {$sidebar = $course_w_heading ; } It looks simple, and it is! However, I had many headaches and false starts getting here. I hope documenting this can help save other beginners some time.
  6. kathep's post in Best way to get random quote displayed on refresh? was marked as the answer   
    @BernhardB Ah, thank you for your many tips! I am learning fast by doing things wrong 
    I am trying your improved code suggestion now...

    UPDATE: It worked! Successful result:

    Below is a breakdown of the steps I took in very simple terms for other beginners to follow (all credit to previous posters, especially @Horst and @BernhardB - you are truly patient ).
    Steps for creating random quote/text selection from a large pool (for an absolute beginner)
    All steps are completed through the ProcessWire admin panel, unless otherwise stated. These steps assume you are using the _main.php and _init.php files in your templates.
    Build a page called tools. This serves as a parent for stuff that is not used to be displayed directly in the frontend. Assign this page the pw_default template. Set the page to hidden. When saving this page, choose 'save + keep unpublished'. Create a new template called quote_category. This template only needs one field: title. Later, you will use the title field of this template to enter categories you want to use to classify quotes.

    Note: this is different to @horst's suggestion of a generic category field only for scalability - if you need to make other categories for other types of information in the future, and don't want them both to be called by the same function.
      In the code editor of your choice, create a file called quote_category.php. In the body of the file, enter:  <?php // quote_categories.php template file Save this file to your computer.  Using an FTP program, upload this file to your processwire installation at: site/templates/. Create a page under tools called quote_categories. This serves as parent for the categories you use to classify your quotes. Assign this page the pw_default template. Set the page to hidden. When saving this page, choose 'publish'. Under the page quote_categories, create child pages. Assign each child page the quote_category template. In the title field of each new child page, enter the name of one category you need. For every child page, set the page to hidden. When saving each child page, choose 'publish'. Create as many child pages as categories you need. Create some fields to be used on a new template (see next step): field label: Quote text
    field name: quote_text
    field type: textarea or text (depending on how long your quotes are, and how much formatting they require) field label: Quote Author
    field name: quote_author
    field type: text field label: Quote Category
    field name: quote_category
    field type: page
    Note: for this field, there are extra settings required - you can find them under the 'Input' section of field options.
    input field type: ASMselect*
    parent of selectable pages: /tools/quote_categories Any other field you need. For example, I have a quote_reference field to cite where the quote came from. This is not necessary though.
      Create a new template called quotes. Add the templates you just created to this template: quote_text, quote_author, quote_category and any others you made.
      In the code editor of your choice, create a file called quotes.php. In the body of the file, enter: <?php // quotes.php template file // Primary content goes here $content = "'" . $page->quote_text . "'". "—". $page->quote_author . "<br>" . "$page->quote_category"; Save this file to your computer.  Using an FTP program, upload this file to your processwire installation at: site/templates/. Create a page under tools called quotes. This serves as parent for all single quote pages.
      Under the page quotes, create child pages. Assign each child page the quote_category template. When saving each child page, choose 'publish'. Create one child page for every quote you have. In an FTP client, download the template where you want a random quote to appear.

    In your code editor of choice, open the template where you want a random quote to appear. Enter the the following code:  $quote = $pages->find("parent=/tools/quotes, quote_category.title=category1|category2")->getRandom(); //add nice formatting $quote_w_heading = "quote: '" . $quote->quote_text . "' —". $quote->quote_author; In the above example, replace the text 'category1|category' with the name of the category/ies you want to display a quote from.

    Then, at the $content or $sidebar function (or wherever you want your quote to display), add the following code to the end of the string: 
    . $quote_w_heading So the $content string should look something like this: 
    // Primary content goes here $content = $course_number_w_heading . $course_summary_w_heading . $recording . $quote_w_heading; Save your template file.
    Upload it back to to site/templates/
     
    In your browser, view a page that uses the template you just changed. Refresh the view, and marvel at your new random quote appearing! Now that I have written out all these instructions, I see that this is perhaps not a beginner project. 
    More experienced people, please offer corrections to any steps you see that could be improved.
    Thanks again all for your help!
×
×
  • Create New...