Jump to content


Photo

Module: Include Other Page


  • Please log in to reply
3 replies to this topic

#1 egecan

egecan

    Newbie

  • Members
  • Pip
  • 6 posts
  • 0

Posted 13 October 2011 - 10:01 AM

Hi,

I created a basic plugin for including the body field from other pages with a special syntax. However, I can't find the module in the "Text Formatters" list. Can you help me identify what I did wrong? Thank you.

<?php

/**
 * ProcessWire Include Other Page Module
 */

class IncludeOther extends Textformatter {

	public static function getModuleInfo() {
		return array(
			'title' => 'Include Other Page', 
			'version' => 100, 
			'summary' => "Includes Other Pages", 
		); 
	}
	
	public static function content_from_id($matches) {
		$id = $matches[1];
		return wire('pages')->get($id)->body;
	}

	public function format(&$str) {
		$str = preg_replace_callback("/\[\[([0-9]+)\]\]/", $this->content_from_id, $str);
	}

}

?>


#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,983 posts
  • 3384

  • LocationAtlanta, GA

Posted 13 October 2011 - 10:51 AM

Welcome to the forums egecan!

The textformatter modules actually have a specific naming convention, so you would want to give your module the class name TextformatterIncludeOther and filename TextformatterIncludeOther.module

I may get rid of this naming convention requirement for Textformatter modules in the future, but I think that it's still in place right now.

If you still don't see it in your list after doing that, go to the "Modules" tab in ProcessWire admin and click "check for new modules" and then click "install" for your module.

One other minor thing to mention is that it's recommended to remove the "?>" from the end of your file. It reduces the chance that some whitespace could get introduced after it, which could interfere with the operation of a site.

#3 egecan

egecan

    Newbie

  • Members
  • Pip
  • 6 posts
  • 0

Posted 13 October 2011 - 11:15 AM

Thank you very much for the explanation. I actually like naming conventions in general and usually promote them but I simply didn't notice this one, or find any mention in the documentation. Is there some place that we can check for these naming conventions? Also, thanks for the tip about the ending "?>". I've actually put it there just because that I was worried that the code beautifier may fail.

On a side-note, I'm new to ProcessWire but it already keeps amazing me. Awesome work.

#4 ryan

ryan

    Hero Member

  • Administrators
  • 5,983 posts
  • 3384

  • LocationAtlanta, GA

Posted 13 October 2011 - 11:32 AM

Thanks, glad that you are enjoying using ProcessWire. Our modules documentation is pretty sparse right now–PW is still a relatively new project and there is still much to do. But I've just updated our existing modules page with a note about naming conventions here: http://processwire.com/api/modules/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users