Jump to content

Recommended Posts

Posted

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);
}

}

?>
Posted

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.

Posted

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.

Posted

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/

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...