Jump to content
Matzn

Add some php code via module

Recommended Posts

Hi.

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->toolbar($ckeditorToolbar);
        $f->attr('name', 'myField');
        $f->useLanguages = true;
        $inputfields->add($f);
		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)
    {
		ob_start();
        eval('?>'.'<?php echo $this->modules->get('Mymodule')->myField ;?>'. '<?php');
        $add = ob_get_contents();
        ob_end_clean();
	
        $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?

Share this post


Link to post
Share on other sites

Hi @Zeka some fields from $page are switch in right language, but not the field from modul. It doesn't matter whether I call up the modul-field in the template or via hook.

 

 

Share this post


Link to post
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;

$modules->get('Mymodule')->get("myField$lable");

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...