joer80

Members
  • Content count

    220
  • Joined

  • Last visited

Community Reputation

68 Excellent

About joer80

  • Rank
    Sr. Member
  • Birthday

Contact Methods

  • Website URL
    http://www.webprojoe.com

Profile Information

  • Gender
    Male
  • Location
    Texarkana, TX

Recent Profile Visitors

2,390 profile views
  1. I think I found the answer.. Instead of using page, you just use pages. It can be at any depth. return $pages->find('parent='/pathofparent/');
  2. When creating a page field that uses Custom PHP code to find selectable pages , the example shows this: Return $page->parent->parent->children("name=locations")->first()->children(); It seems this only works if your page is at a specific depth in the page tree that matches the number of parent-> listed here. If you move the page up a level or down a level, the select will break. Is there a way to return a page array without a specified depth?
  3. I am in a module that is hooking before page save so maybe it would be best if I leave output format off? I am wondering if processwire is expecting that? I dont mind treating it like an array as long as it is expected behavior and not a bug that will be fixed later! Thanks for all your help!
  4. I was able to use output buffering and get it to: result: bool(false) ob_start(); var_dump($page->of()); $result = ob_get_clean(); $event->message("result: " . $result);
  5. var_dump($page->of()); doesnt seem to do anything. If I take off the "->of()" it will print out the page info.
  6. I do further down the page. This is the flow. addHookBefore (save) $event->message("background-image: " . $page->BackgroundImage->url); //Gives background-image: /site/assets/files/1312/ addHookAfter (save) setOutputFormatting(false); (save a different page)
  7. That is what I would have thought also, but it is set to "Single Item (Null if empty)" with 1 as the max images. Looks like it is returning an array no matter what I do.
  8. When I do $page->BackgroundImage->url it gives the path without the filename. Is that normal? I was thinking it gives both. If I do $page->BackgroundImage->url . $page->BackgroundImage I can get it to show both. What am I doing wrong? Thanks!
  9. Here is the version that drops the Themes All Merge field and makes a file instead. (Each page still has a css cache field.) I am using a timestamp on the css filename for cache busting. That way you can set a 6 month time frame on css files and bust out every page save. <?php class CacheThemeCSS extends WireData implements Module { public function init() { $this->pages->addHookBefore('save', $this, 'updateMyCachedCSS'); $this->pages->addHookAfter('save', $this, 'updateThemeCachedCSS'); } //Update the Cached CSS of the page I am on. public function updateMyCachedCSS($event) { //ini $CachedCSS = ''; //Update CSS Cache for page I am on $page = $event->arguments(0); //Prepare CSS for this page $CachedCSS .= '/* ' . $page->title . ' CSS Start */' . "\n"; //Load Item Styles if given if($page->Styles){ $CachedCSS .= '#' . $page->template . '-' . $page->id . '{ ' . $page->Styles . '}' . "\n"; } //Load CSS File Additions if given if($page->CSSAdditions){ $CachedCSS .= $page->CSSAdditions . "\n"; } $CachedCSS .= "\n"; if($CachedCSS){ $page->CachedCSS = $CachedCSS; } } //Update the Themes CachedCSSFilename and make file public function updateThemeCachedCSS($event) { //ini $CachedCSS = ''; //Get all CachedCSS styles $results = $this->wire('pages')->find("CachedCSS!=''"); foreach($results as $result){ $CachedCSS .= $result->CachedCSS; } //Get Active Theme ID $Settings = $this->wire('pages')->get("template=settings"); $FileNameFormat = 'merged_' . date("Y-m-d_H:i:s"); //Get Active Theme so I can update its CachedCSSFilename $ActiveTheme = wire('pages')->get($Settings->ActiveTheme->id); $PreviousCachedCSSFilename = $ActiveTheme->CachedCSSFilename; $ActiveTheme->setOutputFormatting(false); $ActiveTheme->CachedCSSFilename = $FileNameFormat . '.css'; //Set the new value $ActiveTheme->save('CachedCSSFilename'); //make a file with $CachedCSS $myfile = fopen('styles/' . $ActiveTheme->CachedCSSFilename, "w"); fwrite($myfile, $CachedCSS); fclose($myfile); //Delete previous merge file. unlink('styles/' . $PreviousCachedCSSFilename); //$event->message("Old file: $PreviousCachedCSSFilename deleted"); } } //end class
  10. Ok, I think I have it figured out. I ended up putting the cached field in the page also and making 2 functions instead of one. What do you think about this? <?php class CacheThemeCSS extends WireData implements Module { public function init() { $this->pages->addHookBefore('save', $this, 'updateMyCachedCSS'); $this->pages->addHookAfter('save', $this, 'updateThemeCachedCSS'); } //Update the Cached CSS of the page I am on. public function updateMyCachedCSS($event) { //ini $CachedCSS = ''; //Update CSS Cache for page I am on $page = $event->arguments(0); //Prepare CSS for this page $CachedCSS .= '/* ' . $page->title . ' CSS Start */' . "\n"; //Load Item Styles if given if($page->Styles){ $CachedCSS .= '#' . $page->template . '-' . $page->id . '{ ' . $page->Styles . '}' . "\n"; } //Load CSS File Additions if given if($page->CSSAdditions){ $CachedCSS .= $page->CSSAdditions . "\n"; } //$CachedCSS .= '/* ' . $page->title . ' CSS End */' . "\n"; if($CachedCSS){ $page->CachedCSS = $CachedCSS; } } //Update the Themes AllCachedCSS public function updateThemeCachedCSS($event) { //ini $CachedCSS = ''; //Get all CachedCSS and add them to the active themes AllCachedCSS field $results = $this->wire('pages')->find("CachedCSS!=''"); foreach($results as $result){ $CachedCSS .= $result->CachedCSS; } //Get Active Theme $Settings = $this->wire('pages')->get("template=settings"); //Update Active Themes Cached CSS $ActiveTheme = wire('pages')->get($Settings->ActiveTheme->id); $ActiveTheme->setOutputFormatting(false); $ActiveTheme->AllCachedCSS = $CachedCSS; //Set the new value $ActiveTheme->save('AllCachedCSS'); } } //end class
  11. The page tree would be something like: Page 1 Page 2 Theme The gist I was playing with was each page would have a ace rich text box with css in it. On page save it would grab all css from all pages and save to theme. The theme page may want to add to it also though. May have to keep thinking this out. I will make it spit out a css file from that cached field that holds the total output. Add a timestamp for cache busting and have my Page template link the most recent file.
  12. I thought about doing this: if($page->id == $_GET['id']){ $OtherPage->save('ThemeCachedCSS'); //only save the one field instead of whole page } The admin page save click would work because the get var would be set to the page you are on, but it wouldn't loop because the api call page id would be different. It would still loop when editing the theme page though. You would always need it to be a different page than the one you are on.
  13. Ah, I see you posted before me! Thank you for all of your help!