Elxis CMS Forum

Support => Elxis 4.x/5.x DEV => Topic started by: xmanhattan on February 19, 2013, 12:32:21

Title: index or logic files
Post by: xmanhattan on February 19, 2013, 12:32:21
How to do this in index.php and if possible within content?
load external php programs as a link, e.g. add php bot
e.g. displaying category links in the footer using either a module or component

How to do this in index.php or the logic.php?  I looked for something like $eDoc->addLink but didn't find anything in the docs.
load external fonts, e.g.
Code: [Select]
<link href="http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,greek" />
Whether these should be loaded in e.g. the index.php or logic.php files but also considering that the xml file may include a parameter given as a choice and set as a variable, then of course the load should be within the logic.php file.

In other words, when is the decision taken that some coding simply be hard wired into the index.php file rather than the logic.php file?

Also, php logic for if frontpage or not.

Thanks

Title: Re: index or logic files
Post by: webgift on February 19, 2013, 13:33:06
Initialize external font families
Inside the head tag add this line of source code:
eFactory::getDocument()->addStyleLink('http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,greek');

or in case that $eDoc variable has been set as :

$eDoc = eFactory::getDocument();
//change the above line to
$eDoc->addStyleLink('http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,greek');


NOTES
1. On each generated HTML document (or in other words: on each URL) -> A component is running. So you can create (if there is no any) as many modules extending with this way the functionality of a component like: displaying category links in the footer
2. According to the elxis documentation: Templates development guide (https://www.elxis.net/docs/developers/tutorials/templates-guide.html) :
  a. The required - php file Elxis executes is index.php You can use as many others in order to extend the functionality of a template like logic.php or even paranoid.php one. :)
Title: Re: index or logic files
Post by: xmanhattan on February 19, 2013, 14:25:32
I tried using this
Code: [Select]
$eDoc->addStyleLink($oneweb->googleWebFonts); in the logic.php file because I have a parameter to add the link in the template parameters but this is not displaying the link.
Code: [Select]
tplparams['googleWebFonts'] =  link shown in previous post.

Title: Re: index or logic files
Post by: webgift on February 20, 2013, 10:58:39
You can do that in so many different ways.
One way:
- logic.php. Set a new variable with type 'string'
public $gfont = '';

- Inside the getParam method of the existing class
// $this->tplparams['googleWebFonts'] should be the exact URL without single or double quotes.
$this->gfont = $this->tplparams['googleWebFonts'];


- Go to the index.php file inside the head tags
$eDoc->addStyleLink($oneweb->gfont);
or
eFactory::getDocument()->addStyleLink($oneweb->gfont);
Title: Re: index or logic files
Post by: xmanhattan on February 20, 2013, 11:14:36
I received the following error after placing
Code: [Select]
public $gfont = ''; syntax error, unexpected T_PUBLIC.

Code: [Select]
public function addHead() {
$eModule = eFactory::getModule();
$eDoc = eFactory::getDocument();
$elxis = eFactory::getElxis();
public $gfont = '';

// Google fonts styles
if ($this->tplparams['googleWebFonts']  != "copy the css link from Google here") {
//echo '<link href="http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,greek" />'."\n";
//$eDoc->addStyleLink($oneweb->googleWebFonts);
$this->gfont = $this->tplparams['googleWebFonts'];
    }

// other code before and after work
}

Title: Re: index or logic files
Post by: webgift on February 20, 2013, 11:18:27
You have to write this line of source code:
public $gfont = '';
just inside the class of logic.php file NOT inside of any method.

For example:

class logic {
   private $tplparams = array();
   public $gfont = '';

....
}


NOTE:
$this->tplparams['googleWebFonts'] should be set. F.e: http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,greek
Title: Re: index or logic files
Post by: xmanhattan on February 20, 2013, 11:20:35
Ah okay, thanks.

By the way, when it gets warm enough for swimming in Crete I hope that you will accept me for Php class and object lessons!  ;D

Title: Re: index or logic files
Post by: webgift on February 20, 2013, 11:23:34
;)
Yes of course! Lessons with a good μεζέ and wine or even ρακί!