Jump to content

creativejay

Members
  • Posts

    259
  • Joined

  • Last visited

Posts posted by creativejay

  1. Peter, I've added a lot of custom fields to my blog-post template, so my template file for the blog post itself is going to have a lot of calls to the fields listed for the template so that I can't rely on the module to output everything I want in the way that I want. It should be totally possible, and the module has a lot of other features that make it worth my while (multiple authors, the dashboard, etc). Unless you're stripping even more off the blog than just the template output for the individual posts, I think I'd stick with using it. My 2¢!

    • Like 2
  2. Okay, I fixed the mismatched names inside the code (I changed the name to RenameSwatches a few times but the code was still referring to RenamePages). That fixed the 500 error, but nothing happens when I save an existing page.

    I suppose I could add a dialog to see if it thinks it's running.

    Another thought occurs to me.. the field blog_categories is a Page fieldtype. Would that require an adjustment?

  3. @adrian here's the module I made from your code. I'm getting a unexpected T_VARIABLE, expecting T_FUNCTION (line 55) - that would be on "public function renameBeforeSave(HookEvent $event) {"

    <?php
    
    /**
     * ProcessWire 'Rename Page' module by forum user creativejay
     *
     * Checks to see if a page uses the template "blog-post" and has a $page->blog_categories value of "Swatch" then redefines the value of $page->title and $page->name
     * 
     * 
     * ProcessWire 2.x 
     * Copyright (C) 2014 by Ryan Cramer 
     * Licensed under GNU/GPL v2, see LICENSE.TXT
     * 
     * http://processwire.com
     *
     */
    
    class RenamePage extends WireData implements Module {
    
    	/**
    	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
    	 *
    	 * @return array
    	 *
    	 */
    	public static function getModuleInfo() {
    
    		return array(
    
    			// The module's title, typically a little more descriptive than the class name
    			'title' => 'Rename Page', 
    
    			// version number 
    			'version' => 3, 
    
    			// summary is brief description of what this module is
    			'summary' => 'Checks to see if a page uses the template blog-post and has a blog_categories value of Swatch then redefines the value of title and name',
    			
    			// Optional URL to more information about the module
    			'href' => 'https://processwire.com/talk/topic/8863-new-to-hooks-trying-to-wrap-my-head-around-the-syntax/',
    
    			// singular=true: indicates that only one instance of the module is allowed.
    			// This is usually what you want for modules that attach hooks. 
    			'singular' => true, 
    
    			// autoload=true: indicates the module should be started with ProcessWire.
    			// This is necessary for any modules that attach runtime hooks, otherwise those
    			// hooks won't get attached unless some other code calls the module on it's own.
    			// Note that autoload modules are almost always also 'singular' (seen above).
    			'autoload' => true, 
    		
    			// Optional font-awesome icon name, minus the 'fa-' part
    			'icon' => 'eraser', 
    			);
    	}
    $this->addHookAfter('Pages::saveReady', $this, 'renameBeforeSave');
    
    public function renameBeforeSave(HookEvent $event) {
            if($page->template->name === "blog_post" && $page->blog_categories == "Swatches"){
            	$concatenatedName = $page->blog_date;
    		    $concatenatedName .= '-' . $page->createdUser;
    		    $concatenatedName .= '-' . $page->blog_brand;
    		    $concatenatedName .= '-' . $page->blog_name;
    		    
    			$concatenatedTitle = $page->blog_brand;
    		    $concatenatedTitle .= ' ' . $page->blog_name;
    		
    		    $page->title = $concatenatedTitle;
    		    $page->name = $sanitizer->pageName($concatenatedName);
    		    }
            $event->arguments[0] = $page;
    }
    
    

    Can you spot what I've done wrong?

  4. I find it easier to manage these things in a module like this. Also you need to use a before hook, as saving the page with the new title after saving would trigger an infinite loop.

    Thank you! So using the string code from @ESRCH in the "//Do your thing" line of your example, I would then install this module in my site and then it will automatically run, or do I need to call it from somewhere else as well?

  5. I really wanted to create this post with some sample code to show that I at least tried to figure it out on my own first, but I'm really struggling with how hooks are even written. I know it's a very simple context for anyone who's already using them (and hopefully it will be for me, soon), but this is my first time.

    What I'm trying to achieve in this attempt is to verify/change the name and title fields of a page, of one specific template with one specific field, whenever the page is saved.

    Initially, I am using the Family / Name Format for Children to skip the name/title/confirm save page when an author creates a new page in my site using kongondo's ProcessBlog module.

    In English, I want to: Detect when a page of template blog_page is saved with the blog_categories field value of Swatch, and replace the title and name string with a concatenated version of the following fields (from the same page): blog_date, createdUser, blog_brand and blog_name.

    From what I've read so far, I should build this hook into site/templates/admin.php, and I should use the saveReady() and maybe saveField() hooks. Other than knowing I need to define a custom hook, I really haven't got any idea of where to go from here. 

    Here's my mangled first attempt at coding my hook. Hopefully you'll be able to tell how I might be misunderstanding this from the following:

    $pages->addHookAfter('saveReady', $this, 'myPageRename);
    
    public function myPageRename($event) {
     }
    
    

    I'm afraid that's really as far as I've gotten because I have no idea what I'm doing. I try to follow examples but they feel really far removed from context for me.

    Thanks for any light that can be shed on this!

  6. Thanks a bunch Kongondo! I added the extra fields for field type A to a second tab, because I didn't want to distract from the category select field - I was afraid folks would miss that if I didn't put it right at the top! I think I can keep it to two group types.

    Now back to modifying the output with custom templates. Kongondo, thanks as always for the quick support. You're a star!

  7. @Creativejay,

    Did you try my option 2 suggestion above? I tried it and it works brilliantly (tested on lightning.pw so can give you access before the test site expires) .

    Sorry I didn't see this at the time to play in the example you built. I'd love to know more about how you set this up, if it's not too much trouble.

  8. Option 2.

    Add your custom fields to the template 'blog-post' and use the module 'Page Edit Field Permission' to hide your custom fields as relevant to your Posts types A - D. In your template files, you will need to echo your custom fields separately from renderPosts(). I think I would go for this option since it requires the least work and you only have 1 template to deal with..In your template file you would only echo out your custom fields if they were not empty.

    Finally getting back to this project, and I see you tested this with a lot of success. I think I will give this a go. I promise to report back.

    I'm also very excited to see the other features you've added since I last sat down to play around with the blog module, because you've taken care of so many things that were going to be a bother in my case. Thanks again!

  9. Hello apeisa, I'm very excited to see that you are developing this module!

    I've been holding off on adding a cart to a website because of the intricacies of the way my client wants it to work. I see you support variations in PadLoper, and I wondered if I could run a scenario by you to see if your variations will be ... varied.. enough?

    My client makes doll figures to order and there are many options for each one: the color resin it is cast in (which may add to the cost), and optional parts that can be interchanged for either no additional charge or added on for a fee per option. In a single doll order there may be 6 or more options she'll need the customer to select. I might be able to minimize this by one if I separate out the options into separate products, but it would not fit with the way customers are used to shopping for these items if each possible combination has to be a different product.

    Hopefully you have good news for me on that angle!

    In other, less hopeful news, my client also accepts layaway payments for her orders. Usually there is a % deposit, and then the customer makes payments until it is paid off. I don't suspect there is anything you have currently planned that will allow for the customer to come back to manage their layaway payments, but I figured I'd mention it. I saw you have invoicing built in, I wonder if the invoice amount can be edited by the shopkeeper, to invoice for partial payments, multiple times?

    I'm feeling really hopeful about PadLoper, thanks again!

  10. EDIT: Not sure why it didn't work the first time I tried it, but creating a tag without the space or hyphen did eventually work. I'll have to use my workaround (since I can't omit the space in the title of the page). Mods are welcome to delete this post or leave it for someone else who might run into the same thing.

    I thought I was doing something to make life easier on myself (this is how all tragedies begin).

    On a site (live, of course), I had two separate areas where product literature documents were referenced. There is a product literature section, and individual product pages. Before, in each template, I was linking to static URLs for files that were placed on the site via FTP. What usually happened was that I'd upload a file to the Literature section and forget to add it to the product page.

    Yesterday I decided that it would be less complicated (and more fool-proof) to use a File upload field in the Product Literature section, with tags that match the titles of the product pages, so that the product's template could pull from the same files. I thought tags would allow me the flexibility to add any tag I might need down the line.

    With some fits and starts, I got it working yesterday for two categories of document (I thought). Today, I tried to finish up the task and noticed that two of the products are not pulling any documents at all.

    My first instinct, because mysql searches have burned me before, was that the tags "Spectra 500" and "RDS-30" were falling under the search term limits. "Spectra 1000" and "Spectra 1100" work as intended. Reading up in the forums seemed to agree about the search phrase length. I went to the site and did a quick change up of the product page's title and the tags on the document to test, but changing the terms to "Spectra500" and "RDS30" didn't correct it. Later this did start behaving as expected, not sure why I had misleading results from my first attempt.

    So I set up and coded a workaround (thinking a multi-Page Select field on the literature page and a corresponding text field for the product pages).

    Final code to pull files on pages of template "document" using Page Multiselect from the template of pages of template "product":

    		$datasheets = $pages->find("parent=/product-literature/product-data-sheets/,template=document,product_tag=$page");
    		$manuals = $pages->find("parent=/product-literature/product-instruction-manuals/,template=document,product_tag=$page");
    		if(count($datasheets)) { 
    					echo "<div class='col span_2_of_4'>";
    						echo "<section class='reports'>";
    							echo "<h4 class='section_names'>Available Product Documentation</h4>";
    							foreach($datasheets as $datasheet) {
    								echo "<div>";
    								$datasheetLink = $datasheet->get("254_file")->url;
    								echo "<a href='{$datasheetLink}' target='doc_window'><img src='{$config->urls->assets}images/documenticon.png' class='floatleft' alt='{$datasheet->title}'>";
    								echo "<p class='file_names'>{$datasheet->headline}</p></a>";
    								echo "</div>";	
    							}	
    						if(count($manuals)) {
    							foreach($manuals as $manual) {
    								echo "<div>";
    									$manualLink = $manual->get("254_file")->url;
    									echo "<a href='{$manualLink}' target='doc_window'><img src='{$config->urls->assets}images/documenticon.png' class='floatleft' alt='{$manual->headline}'>";
    									echo "<p class='file_names'>{$manual->headline}</p></a>";
    								echo "</div>";	
    								}
    							}
    							echo "<br /> <br /></section>";
    							echo "</div>";
    				} else if(count($manuals)) { 
    					echo "<div class='col span_2_of_4'>";
    						echo "<section class='reports'>";
    							echo "<h4 class='section_names'>Available Product Documentation</h4>";
    							foreach($manuals as $manual) {
    								echo "<div>";
    									$manualLink = $manual->get("254_file")->url;
    									echo "<a href='{$manualLink} target='doc_window'><img src='{$config->urls->assets}images/documenticon.png' class='floatleft' alt='{$manual->headline}'>";
    									echo "<p class='file_names'>{$manual->headline}</p></a>";
    								echo "</div>";	
    								}
    								echo "<br /> <br /></section>";
    							echo "</div>";
    				}
    
  11. Thanks, everyone, for your tips, advice, and experience!

    My current plan is to create the table structure in the new site and code and output a CSV file from MODx, and import that into the new site via ImportPagesCSV.

    Luckily this is my primary concern with the site so if it foos the bar, I'm happy to wipe it and start over until I get it right, then flesh out the rest.

    The next problem to tackle is making sure my URLs (ending in .html from MODx) match, to avoid having to set up some excruciating redirects. But I have yet to look into that, so unless you know the exact thread I need to look at, no worries answer that one here! :)

  12. @teppo thank you so much for your reply! I have never worked with so much data in a site migration before that a manual copy/paste wasn't easier than learning the proper way to get data from one db to another. I'm able to work with an otherwise undeveloped install, so I have room to make some mistakes, this time.

    Import Pages CSV looks very promising as well, and I'm excited to see it because it potentially answers the call from another site I'm building where I hope to import a blogger CSV export into the new site structure.

    Thanks again!

  13. Hello everyone!

    I've built several Processwire sites now and I just love the framework more and more with each successful launch.

    I'm about to tackle what is, to me, a huge site redesign, taking a large catalog-style site and updating it from MODX's evo to PW 2.5 (assuming there isn't a 2.6 by the time I finish..).

    The site is modest as far as catalogs go, but while I could copy-paste tV values into PW custom fields, I feel like there has to be a solution I can execute via myPHPAdmin with the right site setup in processwire's admin.

    My MODX Install (henceforth known as Current Site) has a resource for each product, and tied to that resource's template are any number of ≤70 template variables.

    Ideally, I'd like to plan an approach that lets me export the values for the Current Site's TVs from the database, and import it into fields in the Processwire Install (henceforth New Site).

    It appears to me that the Current Site's tables are built with page content and TVs in one table, whereas the New Site's PWire structure is not as one-to-one as the MODX method. So I have to untangle some yarn, first, to figure out what to import and where, if I understand it correctly.

    Would it be a pursuit of madness to try what I'm thinking? Does anyone have any experience with this? Is there something else you'd recommend instead?

    Thank you!

  14. Okay, I think I have a question worthy of typing now...

    In my particular case, there are three types of templates for my blog's content, depending on which of four categories it is posted in. Because I'd like to require some of these fields only in certain categories, I don't want to just add the fields and only render them for certain pages because if I require them for posts that won't show them that might annoy my authors. If I don't require them my authors may not include them when I actually need them.

    Example:

    Category A - Uses Template A with Field Group A (blog posts with lots of extra fields)

    Category B - Uses Template B with Field Group B (standard blog post, pretty much what you created as default)

    Category C - Uses Template C with Field Group C (no description area, one image with caption and tags, plus title)

    Category D - Uses Template B with Field Group B(standard blog post, pretty much what you created as default)

    I was hoping that under the settings for each individual category I could pick what type of template their children could use. When I added my Template_A_post to the allowed children for Category A, I was able to edit an existing post from that category and change the template to Template_A_post, but when the blog posts list refreshed, it disappeared. So this is more problematic than just allowing different templates, it seems. Template_A_post is a clone of the blog-post template with a couple extra fields added so far.

    Can you suggest a way to do this within the ProcessBlog module without fiddling with the module files themselves? I'm running ProcessBlog 1.3 in PWire 2.5.

    As I mentioned before, I have been planning this blog for a while. My original plan (as of early 2013) was to use a different form in FormBuilder to create pages in each category, using specific templates, on form submit.

    Update: I can combine my original plan with the new blog module, by creating FormBuilder forms with the information I want and passing it to blog post, which has all custom fields as optional. This might actually work out well, as I could create a whole 'front-end-back-end' for my contributors so I can avoid customizing the admin as much as I thought I might need. Do let me know if you see a way to create custom blog templates directly, though!

  15. @kongondo thank you so much for this module, it's exactly what I need for a site I've been wanting to get around to for two years. Now I'm glad I never got the chance before! Your documentation for it is beautiful, as well. I appreciate the time and effort that went into it!

    // removed question because I found my answer. ;)

    • Like 1
  16. This page is exhibiting issues with the output of my right column sidebar, which is built in a function. It appears fine on the initial page, but when clicking to the additional pages, anything output by the functions eventsListSidebar and docListSidebar disappears.

    http://www.spectra254.com/about-us-test/news-test/

    Hoping someone could lend me their eyes and point out what might be the culprit.

    Function code (254_functions.inc):

    function eventsListSidebar(){
     
    	$events = wire("pages")->find("parent=/about-us/events/,template=254_events,include=hidden,limit=3,sort=event_startDate");
     
    	$out .="<ul>";
    		
    	//Loop through the pages
     
    	foreach($events as $event){
    		$startMonth = date(n, $event->event_startDate);
    		$endMonth = date(n, $event->event_endDate);
    		
    		if ($endMonth > $startMonth) { 
    			$startDateFormatted = date('j M', $event->event_startDate);
    			$endDateFormatted = date('j M', $event->event_endDate);
    		} else {
    			$startDateFormatted = date('j', $event->event_startDate);
    			$endDateFormatted = date('j M', $event->event_endDate);
    		}
    		$out .="<li><h3 class='sub_header_2'>{$startDateFormatted} – {$endDateFormatted}</h3>";
    		$out .="<p>{$event->title}<br />";
    		if($event->event_city){
    			$out .="{$event->event_city} <br />";
    		} else { $out .="";}
    		if ($event->event_booth){
    			$out .="{$event->event_booth}";
    		} else { $out .="";}
    		$out .="</p></li>";
     
    	}
    	$out .= "</ul>";
    	echo $out;
     
    }
    
    function docsListSidebar(){
     
    	$docs = wire("pages")->find("parent=/product-literature/,template=document,limit=5,sort=sort");
     
    	$out .="<ul>";
    		
    	//Loop through the pages
     
    	foreach($docs as $doc){
    		$out .="<li><div><a href='{$doc->Link}' target='_blank'><img src='";
    		$out .=wire("config")->urls->assets; 
    		$out .="images/documenticon.png' alt='{$doc->title}' class='floatleft' /><span style='display: block;height: 15px; padding-top:5px;'>{$doc->title}</span></a></div></li>";
    	}
    	$out .= "</ul>";
    	echo $out;
     
    }
    
    

    output for /news-test/ called as newsList() within that same 254_functions.inc file:

    function newsList(){
     
    	// Grab the page name from the url
     
    	$thisCategory = wire("page")->name;
     
    	// If the category is not called "news" then output the category name as a selector for the find.
     
    	if($thisCategory !="news") {
    		$category = "article_category.name=" . $thisCategory;
    	}	
     
    	// Get the news posts - limited to ten for later pagination
     
    	$newsposts = wire("pages")->find("template=254_news_article,limit=5,sort=-published_date");
     
    	$out =" ";
     
    	//Loop through the pages
    	$out .="<div class='pagination'>";
    	$out .= $newsposts->renderPager(array(
     
    				    'nextItemLabel' => "Next",
    				    'previousItemLabel' => "Prev",
    				    'listMarkup' => "<div class='pagination'>{out}</div>",
    				    'itemMarkup' => "<span class='pagelink'>{out}</span>",
    				    'linkMarkup' => "<a href='{url}'>{out}</a>"   
     
    					));
    	$out .="</div>";
    
    	foreach($newsposts as $child) {
    		$target = $child->get("Link|url");
    		$out .= "<div class='simple-row'>";
    		
    		if($child->prod_image) {
    			$img = $child->prod_image;
    								
    			if($img->width > $img->height) {              // check for orientation
    				$thumb = $img->width(150);  // we have a landscape oriented image
    			 } else {
    				$thumb = $img->height(150);     // we have a portrait oriented image
    			 }
    		
    			$out .= "<span style='display: block; width: 150px; height: 150px;float: left; margin-right: 25px;'><a href='{$target}'><img src='{$thumb->url}' class='floatleft' alt='{$child->get("title")}'></a></span>";
    			}
    			
    		$out .="
    		<div class='text-float'>
    		<h2 class='bold_sub_title'><a href='{$target}'>{$child->get("headline|title")}</a></h2>";
    		$out .= "<div class='text_block'><p>";
    		$content = $child->body;
    		$out .= limit_words($content,30);
    		$out .= "... <a href='{$target}'>Read More</a></p></div>
    		</div>
    		</div>";
    }
    
    	// Pagination
     
    	$out .="<div class='pagination'>";
    	$out .= $newsposts->renderPager(array(
     
    				    'nextItemLabel' => "Next",
    				    'previousItemLabel' => "Prev",
    				    'listMarkup' => "<div class='pagination'>{out}</div>",
    				    'itemMarkup' => "<span class='pagelink'>{out}</span>",
    				    'linkMarkup' => "<a href='{url}'>{out}</a>"   
     
    					));
    	$out .="</div><div style='display:block; width: 100%; height: 35px;'></div>";
     
    	echo $out;
     
    }
    
    

    the sidebar itself renders in 254_foot.inc (this is just the segment pertaining to the above)

    if($page->template == "254_news") {
    		echo "<div class='col span_1_of_4'>
    			<div class='about_side_bar'>
    				<h2>Product Literature</h2>";
    				docsListSidebar();
    				echo "<div style='display: block; height: 1em; width: 100%;'></div>";
    				echo "<h2>Tradeshow Schedule</h2>";
    				echo "<br ><a href='{$pages->get(1024)->url}'>View the Full Schedule</a>";
    				eventsListSidebar();
    				echo "
    			</div>
    		</div>";
    		}
    

    Thanks in advance!

  17. Soma, since you pointed me to it specifically, I just wanted to let you know that I was able to use ImagesManager for my project and it fit the bill completely. Thanks for taking the time to work on image gallery management for PW!

    • Like 4
  18. If you take it now. You'll get two stock free images and a T-Shirt for free! 

    Ha ha, I'll just be happy if it's what I've been hoping for!

    It was the Gallery module for MODX that drove me away (I am hosted on a shared server), since it was actively scanning the folders in my directory and displaying the images (and creating new thumbnails) each time. My host was very patient (though stern) but I ran out of time to work on the problem and kept finding forum posts about how it's insane to try and host Revo on a shared server, so I went looking for better solutions and wound up here! I like the flexibility and the promise that I'll be able to use my brain cells on php again. And just in time, I have a project that's probably 85% finished in MODX but I'm more than willing to start over in PW if it's going to be kinder to my server. ImagesManager looks like a big step in the right direction.

×
×
  • Create New...