development question

serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 08:41

gentlemen,
it is possible for a view to load a TPL file that is located in the g2data structure ?

regards,
serbanc - www.e-poze.ro

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2007-11-26 11:02

yes. it's just a matter of specifying the template path when loading the .tpl file.
but the output of TinyMCE isn't a .tpl file, is it?
i guess you'd just store the HTML as a .html or .dat file as a normal g2 item. so you don't have to worry where it's stored. it's stored for you in g2data/albums/.
then you could embed that html in a normal view .tpl of your module.

but if this is really about the HTML item task, let's continue the discussion in your existing thread at http://gallery.menalto.com/node/71171. :)

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 11:49

valiant, thank you very much for your answer.
the question is not related to HTML item module.

Story.
I want to develop a module that allows me to put a different page as home page.
Mainly, I managed to develop something, but I hate to go on telnet/ftp to modify the TPL file each time.

So one ideea would be to store a .TPL file somewhere (let's say in g2data dir) and, via some simple administration tool, to be able to edit it (web interface).

serbanc - www.e-poze.ro

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2007-11-26 13:28

you could also store the HTML in the database.

@g2data:
each module can store plugin data.
example: the watermark module stores its watermark files at:
$gallery->getConfig('data.gallery.plugins_data') . 'modules/watermark/';

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 13:42

ok, I am posting the code below.
What I want is to store FrontPage.tpl file somewhere in g2data (details below).
And to be able to load it. the commented return lines are not working. do not know why.

And now, the code:

class FrontPageView extends GalleryView {

/**
* @see GalleryView::loadTemplate
*/
function loadTemplate(&$template, &$form) {
global $gallery;

/* get the default file */
list ($ret, $value) =
GalleryCoreApi::getPluginParameter('module', 'frontpage', 'frontPageFile');
if ($ret) { return array($ret, null); }

$platform =& $gallery->getPlatform();
$slash = $platform->getDirectorySeparator();
$frontpageDir =
$gallery->getConfig('data.gallery.plugins_data') . 'modules/frontpage' . $slash;

$tplFile = $frontPageDir . $value;

// return array(null, array('body' => $tplFile,
// 'useFullScreen' => TRUE));

return array(null, array('body' => 'modules/frontpage/templates/FrontPage.tpl',
'useFullScreen' => TRUE));
}

serbanc - www.e-poze.ro

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2007-11-26 14:26

i guess you'd have to smarty->fetch your .tpl separately. then pass the rendered HTML as a param to another template.
(or use an immediate view instead)

alternative 1, normal view:

add a new .tpl at gallery2/modules/frontpage/templates/FrontPage.tpl with the contents:

{$FrontPage.html}[/codde]

In your view, add:

[code]
$separateTemplate = new GalleryTemplate($frontpageDir);
$separateTemplate->setVariable('l10Domain', 'modules_frontpage');
/* Render the template */
list ($ret, $html) = $separateTemplate->fetch($value); // $value being the name of the your .tpl in plugins_data/modules/frontpage/
if ($ret) {
    return array($ret, null);
}

$template->setVariable('FrontPage', array('html' => $html));
return array(null, array('body' => 'modules/frontpage/templates/FrontPage.tpl'));

alternative 2: store the HTML in a plugin parameter instead of storing it as a file:
- create a templates/FrontPage.tpl file as described above.
- change your view accordingly

list ($ret, $html) =
GalleryCoreApi::getPluginParameter('module', 'frontpage', 'html');
if ($ret) { return array($ret, null); }
$template->setVariable('FrontPage', array('html' => $html));
return array(null, array('body' => 'modules/frontpage/templates/FrontPage.tpl'));

alternative 3: use an immediate view:
basically like alternative 1 and 2, but instead of assigning the HTML as template variable, you'd just print it out.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 16:14

Thanks Valiant,
I will test it asap. let you know about the status.
serbanc - www.e-poze.ro

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 17:40

Valiant, I used version 1.
Works great, with one exception: I cannot display SystemLinks blocks. Looked into core/...../SystemLinks.tpl and it gets the links from $theme.SystemLinks. I imagine that working with separate template, I will not have the theme variable defined. Now the question: how can I load the SystemLinks for a theme ???
serbanc - www.e-poze.ro

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 18:24

solved! loaded the default theme!
thanks for your support.

serbanc - www.e-poze.ro

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-11-26 20:44

valiant, thank you very much for your support.
It works perfect!

serbanc - www.e-poze.ro

 
serbanc

Joined: 2006-05-19
Posts: 314
Posted: Mon, 2007-12-10 10:32

Gentlemen,
Managed to finalize some sort of primitive FrontPage module and I would like to share it.

What should I do ?

serbanc - www.e-poze.ro

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2007-12-11 14:51

make a zip file and create a new forum topic to announce your module with the zip file attached as forum file attachement.
usually modules are announced in the module development forum. (this will change next year)

also add your module on the wiki pages. downloads -> user contributed modules. and codex.gallery2.org/Gallery2:Modules:yourmoduleid

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage