Elxis CMS Forum

Support => Elxis 4.x/5.x DEV => Topic started by: xmanhattan on February 14, 2013, 13:17:13

Title: template coding problem
Post by: xmanhattan on February 14, 2013, 13:17:13
I am using code from another template and trying to modify a template that I found but I am receiving an error.

Code: [Select]
    private function getParams() {
        $eModule = eFactory::getModule();
        elxisLoader::loadFile('includes/libraries/elxis/parameters.class.php');
        $xmlpath = ELXIS_PATH.'/templates/oneweb/oneweb.xml';
        $tplparams = $this->getDBParams();       
        $params = new  elxisParameters($tplparams, $xmlpath, 'template');

$this->tplparams['loadMoo'] = $params->get('loadMoo');
$this->tplparams['jQuery'] = $params->get('jQuery');
$this->tplparams['modernizr'] = $params->get('modernizr');
$this->tplparams['badBrowser'] = $params->get('badBrowser');
$this->tplparams['scripts'] = $params->get('scripts');
$this->tplparams['frontpage'] = $params->get('frontpage');
$this->tplparams['setGeneratorTag'] = $params->get('setGeneratorTag');
$this->tplparams['analytics'] = $params->get('analytics');
$this->tplparams['verification'] = $params->get('verification');
$this->tplparams['googleWebFonts'] = $params->get('googleWebFonts');

        unset($params); //free memory

// Calculate the number of modules published in a positon
$aboveModules = ($eModule->countModules('above1')?1:0)+ ($eModule->countModules('above2')?1:0)+ ($eModule->countModules('above3')?1:0)+ ($eModule->countModules('above4')?1:0);

$bottomModules = ($eModule->countModules('bottom1')?1:0)+ ($eModule->countModules('bottom2')?1:0)+ ($eModule->countModules('bottom3')?1:0)+ ($eModule->countModules('bottom4')?1:0)+ ($eModule->countModules('bottom5')?1:0)+ ($eModule->countModules('bottom6')?1:0);

$footerModules = ($eModule->countModules('footer1')?1:0)+ ($eModule->countModules('footer2')?1:0)+ ($eModule->countModules('footer3')?1:0)+ ($eModule->countModules('footer4')?1:0);

        unset($eModule);
}


// further down I have this on line 119

if ($modernizr) {
$eDoc->addScriptLink('<script src="'.$template.'/js/modernizr-2.5.3.min.js"></script>');
}


I am receiving this as an error message:
ERROR in file C:\wamp\www\nautilus\templates\oneweb\logic.php line 119
syntax error, unexpected T_IF, expecting T_FUNCTION

I can set the parameters under the Edit Template to load modernizr but I don't see my error here.


Title: Re: template coding problem
Post by: webgift on February 14, 2013, 13:27:07
$modernizr variable haven't been defined. So you should change the if statement to
if ($this->tplparams['modernizr'])


//It's my 1st note that.
Title: Re: template coding problem
Post by: datahell on February 14, 2013, 13:34:45
No, this is not the problem.
The problem is that you miss a closing bracket "}". Check the whole of your code and see where you miss the bracket.
Title: Re: template coding problem
Post by: webgift on February 14, 2013, 13:38:13
True. I supposed that it's 2 different parts.
Title: Re: template coding problem
Post by: xmanhattan on February 14, 2013, 13:46:10
I must be going blind because I cannot find the missing bracket.  I made the other change to the first two errors.

This is the file if you don't mind looking at it.
Title: Re: template coding problem
Post by: webgift on February 14, 2013, 13:49:09
Remove the closing bracket from line 69 and add it to line 161.
Title: Re: template coding problem
Post by: xmanhattan on February 14, 2013, 13:52:52
I received a new error.  ERROR in file C:\wamp\www\nautilus\templates\oneweb\logic.php line 95
Can't use method return value in write context

Title: Re: template coding problem
Post by: webgift on February 14, 2013, 14:19:17
Check this out. Toooo many errors
Title: Re: template coding problem
Post by: xmanhattan on February 14, 2013, 15:01:40
I'm probably biting off more than I can chew but I will try to get it working.

Thanks
Title: Re: template coding problem
Post by: xmanhattan on February 14, 2013, 17:21:36
What is wrong with this?  I have them in the logic.php and I am seeing multiple
Quote
[:head:] [:head:][:head:][:head:][:head:][:head:][:head:]
appearing.

Code: [Select]
// Site icons: http://mathiasbynens.be/notes/touch-icons
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" sizes="144x144" href="'.$template.'/images/large/apple-touch-icon.png">');

// Metas
$eDoc->showHead( 'HandheldFriendly', 'True' );
$eDoc->showHead( 'MobileOptimized', '320' );
Title: Re: template coding problem
Post by: datahell on February 14, 2013, 19:09:49
You use addScriptLink wrong. You should provide only the url and also the url you provide is not a script, but a png image!
Checkout the documentation: https://www.elxis.net/docs/developers/libraries/elxisdocument.html (https://www.elxis.net/docs/developers/libraries/elxisdocument.html)

Correct example:
$eDoc->addScriptLink('http://www.example.com/test/something.js');

What the f... is this: $eDoc->showHead( 'HandheldFriendly', 'True' );
Where did you find that? showHead doesn't have any input arguments, it just echoes the page's head section. Use it as on template Delta.

Dont add other than the built in JQuery. To load JQuery:
$eDoc->addJQuery();

Other javascript libraries should be loaded with the addLibrary method.
Why to use both jquery and mootools on the same page?

Example:
$eDoc->addLibrary('mootools', 'http://www.example.com/something/mootools.js', '1.3');

It looks like you didn't read the documentation at all.
Title: Re: template coding problem
Post by: xmanhattan on February 15, 2013, 10:32:01
My error but I did not find any info on showhead in the documentation except for one line on this page.  Actually I have read much of the documentation awhile back but I did not see the template info until now.
https://www.elxis.net/docs/developers/tutorials/templates-guide.html (https://www.elxis.net/docs/developers/tutorials/templates-guide.html)
By the way, the simplicity download does not work. Invalid request!

What I am trying to do is to convert a template and the objects that it uses is trying to add meta links to the output.

I looked at https://www.elxis.net/docs/developers/libraries/elxisdocument.html (https://www.elxis.net/docs/developers/libraries/elxisdocument.html) and found
setMetaTag
public function setMetaTag($name, $content, $equiv=false)
Sets any META tag (generator, description, author, etc).
so I tried to do it using that.

By the way, you didn't comment on the favicon link which also produces an error.  I set them like this:
Code: [Select]
// Site icons: http://mathiasbynens.be/notes/touch-icons
// For third-generation iPad with high-resolution Retina display:
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" sizes="144x144" href="'.$template.'/images/large/apple-touch-icon.png">');

//For iPhone with high-resolution Retina display:
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" sizes="114x114" href="'.$template.'/images/large/apple-touch-icon.png">');
// For first- and second-generation iPad:
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" sizes="72x72" href="'.$template.'/images/medium/apple-touch-icon.png">');
// For non-Retina iPhone, iPod Touch, and Android 2.1+ devices:
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" href="'.$template.'/images/small/apple-touch-icon-precomposed.png">');
but I am not sure if they will all be output based on the setFavicon and getFavicon.

I know that I am not up to par on php 5.3 but I make every attempt at getting it right.  When it doesn't I go to the pros like you ( and others on this forum).

Thanks for you help.
Title: Re: template coding problem
Post by: webgift on February 15, 2013, 10:52:47
I checked the download link of simplicity template and it's working. Can you please verify that?
The txt file, that i attached you yesterday, have some errors. I leave them as it is in order to find out by yourself.

Here are some available methods of elxisDocument Library.

//ADD STYLE SHEET LINK
eFactory::getDocument()->addStyleLink($url, $type='text/css', $media='', $attribs='');

//ADD RAW STYLE
eFactory::getDocument()->addStyle($content, $type='text/css');

//ADD UNIQUE SCRIPT LIBRARY (JQUERY, MOOTOOLS, ETC...)
eFactory::getDocument()->addLibrary($name, $url, $version='1.0');

//ADD JQUERY
eFactory::getDocument()->addJQuery();

//ADD SCRIPT LINK
eFactory::getDocument()->addScriptLink($url, $type='text/javascript');

//SET FAVICON
eFactory::getDocument()->setFavicon($url);
Title: Re: template coding problem
Post by: xmanhattan on February 15, 2013, 11:36:28
Simplicity link is now working.

So these are not equivalent?
Code: [Select]
$eDoc->addScriptLink($template.'/js/helper.js');
Code: [Select]
eFactory::getDocument()->addScriptLink($template.'/js/helper.js', $type='text/javascript');
or these?
Code: [Select]
$eDoc->addScriptLink('<link rel="apple-touch-icon-precomposed" sizes="144x144" href="'.$template.'/images/large/apple-touch-icon.png">');
Code: [Select]
eFactory::getDocument()->setFavicon('<link rel="apple-touch-icon-precomposed" sizes="144x144" href="'.$template.'/images/large/apple-touch-icon.png">');
Title: Re: template coding problem
Post by: datahell on February 15, 2013, 12:47:26
Peter you use the functions wrong. Check carefully what we have written and the documentation.
Title: Re: template coding problem
Post by: xmanhattan on February 17, 2013, 12:33:42
I have managed to figure out many of the errors after experimenting and now have partial working template pages.

Questions:
Because the template positions have different names than the Nautilus installation, how or can I assign / create position names and if possible settings such as dimension using php?  e.g. The template positions have multiple blocks of above 4 times across.
If this is incorrect logically then maybe the next question is more correct.

How can a specific module be placed in the template?  e.g. under module position frontpage2 there is articles and popular articles.
Is there a way to display a module position but calling a specific module?  e.g.
Code: [Select]
$eDoc->modules('frontpage2 articles');or does each module position have to be changed manually?

Can you provide an example of how to inject additional meta tag information?

Pls see this link for positions http://joomlafuture.com/2012-04-26-17-26-41 (http://joomlafuture.com/2012-04-26-17-26-41)
Title: Re: template coding problem
Post by: datahell on February 17, 2013, 14:19:02
1. It is bad practice to use many custom module positions. Try use the standard ones especially in important positions.

2. You can automatically create these template positions during template install. All extensions, including template, may have an optional install.php file. Inside this file you can set the actions to be performed during install/update/uninstall. A brief presentation can be found in modules development guide (https://www.elxis.net/docs/developers/tutorials/modules-guide.html).

To create a new module position during install put a code like the one below inside your "install" method.

Code: [Select]
public function install() {
     elxisLoader::loadFile('includes/libraries/elxis/database/tables/tplpositions.db.php');
     $row = new tplpositionsDbTable();
     $row->position = 'youhoo';
     $row->description = 'Some description';
     $row->insert();
}

If you have more than 1 position use forceNew method and repeat:
Code: [Select]
$row->forceNew(true);
$row->position = 'kookoo';
$row->description = 'Some description';
$row->insert();

$row->forceNew(true);
$row->position = 'baaboo';
$row->description = 'Some description';
$row->insert();

Examples on adding custom meta tags:

Code: [Select]
$eDoc = eFactory::getDocument();
$eDoc->setMetaTag('owner', 'Ioannis Sannos');
$eDoc->setMetaTag('revisit-after', '30');
$eDoc->setMetaTag('refresh', '20', true);
Title: Re: template coding problem
Post by: xmanhattan on February 17, 2013, 15:42:25
Thank you Datahell.