Jump to content

Add some php code via module


Recommended Posts


To manipulate the page output i use the hook Page::render. It works for html, php etc without touch the templatefiles. Example i build a modul called "Mymodul" and integrate some multilanguages fields:

class MymodulConfig extends ModuleConfig
	public function getInputfields()
        $inputfields = parent::getInputfields();  
		$ckeditorToolbar ='Format, Bold, Italic, -, RemoveFormat';

        $f = $this->modules->get('InputfieldCKEditor');
        $f->attr('name', 'myField');
        $f->useLanguages = true;
		return $inputfields;

and add it to all pages:

    public function ready()
        if ($this->page->template != 'admin') {
            $this->addHookAfter('Page::render', $this, 'addSome');

    public function addSome($event)
        eval('?>'.'<?php echo $this->modules->get('Mymodule')->myField ;?>'. '<?php');
        $add = ob_get_contents();
        $event->return = str_replace("</body>",  $add . "</body>", $event->return);

What i'm missing are the variables for $languages and the switching of the multi languages fields from module. Does somebody has any idea why get only the default language field from modul?

Link to comment
Share on other sites

Ok, it seems as if the fields are only translated for the Pageobject. Either you create a page and moves all fields there or you call up the fields of the modules include the suffix as follows:

english: myField

german: myField__1024

if ($user->language->name != "default")	$lable =  "__" . $user->language->id;



Link to comment
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

  • Recently Browsing   0 members

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