Jump to content
HubertZ

Creating a new content module

Recommended Posts

hi,

 

i'm using a fresh installed v2.3.4

 

Now i want to add some text (under the navbar) through a module (editable via admin)

This is what i tried:

<?php
// includes/modules/content/foo/foo.php

class foo {
    var $code;
    var $group;
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
    
    function foo() {
	$this->code = get_class($this);
	$this->group = basename(dirname(__FILE__));
	
	$this->title = MODULE_FOO_TITLE;
	$this->description = MODULE_FOO_DESCRIPTION;
	
	if ( defined('MODULE_FOO_STATUS') ) {
	    $this->sort_order = MODULE_FOO_SORT_ORDER;
	    $this->enabled = (MODULE_FOO_STATUS == 'True');
	}
    }
    
    function prepare() {
	global $oscTemplate;
	/* whats this for */
    }
    
    function build() {
	global $oscTemplate;
	
	$output = 'where am i built: '. MODULE_FOO_TEXT;
	
	$oscTemplate->addContent($output, $this->group);
    }
    
    function execute() {
	global  $oscTemplate;
	$output = 'where am i executed: '. MODULE_FOO_TEXT;
	$oscTemplate->addBlock($output, $this->group);
    }
    
    function isEnabled() {
	return $this->enabled;
    }
    
    function check() {
	return defined('MODULE_FOO_STATUS');
    }
    
    function install() {
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('foo Module', 'MODULE_FOO_STATUS', 'True', 'Enable foo?', '6', '', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_FOO_SORT_ORDER', '1500', 'Sort order halt.', '6', '', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Text', 'MODULE_FOO_TEXT', 'buy this it\'s good', 'Enter text', '6', '8', now())");
    }
    
    function remove() {    
	tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
    
    function keys() {
	return array('MODULE_FOO_STATUS', 'MODULE_FOO_SORT_ORDER', 'MODULE_FOO_TEXT');
    }
	    
}
?>

then

<?php
// includes/languages/english/modules/content/foo/foo.php

define('MODULE_FOO_TITLE', 'foo title');
define('MODULE_FOO_DESCRIPTION', 'foo descr');

?>

I can enable/disable this as admin in 'content, foo' edit and save text, but i don't see the text nowhere in the index.php page (source) when i reload it afterwards.

 

What am i missing?

I 'stole' that code from some example modules i downloaded, as i didn't find any docs on this topic...

 

ciao,

HubertZ

 

Share this post


Link to post
Share on other sites

@@HubertZ

You have to call the module there where you would like to show the text.

<?php echo $oscTemplate->getContent('foo'); ?>
Edited by Tsimi

Share this post


Link to post
Share on other sites

@HebertZ

 

This test foo module will be called by the

$this->group = basename(dirname(__FILE__));

So depending which folder you dropped this cm into, it will be launched.   Tsimi comments above would require you to create a folder 'foo' in the content folder under modules.

 

As you want this under the navbar, it would be best suited for the header folder.

 

Also, looking at your code, I am not sure which module you copied this from; however, the functions prepare or build are not required to accomplish what you require.

Share this post


Link to post
Share on other sites

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

×