1
phatjew
template not automatically recompiled
  • 2003/11/18 18:51

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Hey there,

I am a template newbie, so please tell me if I am doing something wrong.

When I change a template, in my experience it is NOT automatically recompiled. I have to manually update the module via the admin page to see the change. Is this true for everyone?

This is especially important during develoment, because I am constantly making changes and I want to be able to see the result without having to go to the admin=>module page and clicking the "Update" button every single time.

--Rafi

2
ackbarr
Re: template not automatically recompiled

what you are experiencing is accurate - once a module is installed the template contents are extracted from the template files and added to the XOOPS database. So when you change the file in the 'templates' directory XOOPS does not know about it until the module is updated in System -> Modules.

What I do to minimize this modify -> reload -> retry cycle is to develop modules from the outside in. This means that I develop my modules in the following order:
html mockup
templates
frontend php pages
blocks
admin
php classes
database schema

Ok. Not exactly like that, many times I have the db schema / class structure in my head from the very beginning, but I don't actually write any of the lower level code until I know how I am going to be using it.

3
phatjew
Re: template not automatically recompiled
  • 2003/11/18 19:01

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


OK, fair enough.

Is there a way to invoke some XOOPS code to recompile the templates EVERY TIME a page is loaded? I am thinking about a line like:

$xoopsOption['compile_templates'] = 'true';

I could use this during development, then comment it out or delete it once I am finished.

Does anything like this exist?

4
phatjew
Re: template not automatically recompiled
  • 2003/11/18 19:09

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Holy Crap! It's in the Wiki!


Quote:

'theme_fromfile' - when set to "1", XOOPS automatically checks your theme files to see if they have been update; if so, database templates are updated


If only there was something that checked a module's template files, not just the theme template file. It seems like most of the code is already written . . .


5
Mithrandir
Re: template not automatically recompiled

There is a smarty variable, which can force a compile ($force_compile if I am not mistaken) which does exactly that - but the problem is that the templates in XOOPS are moved to the database, so it needs a bit of extra work here.

but as you say, most code is written... maybe possible to extend to module area.

What is really a bitch is if you use a non-default template set on your site Cause on module update, it updates the default template in database only.

6
phatjew
Re: template not automatically recompiled
  • 2003/11/18 19:44

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Quote:

MithyT2 wrote:
There is a smarty variable, which can force a compile ($force_compile if I am not mistaken) which does exactly that - but the problem is that the templates in XOOPS are moved to the database, so it needs a bit of extra work here.

but as you say, most code is written... maybe possible to extend to module area.



I'd be willing to give it a shot if someone could point me in the right direction. I just haven't done a whole lot of excavating through the XOOPS core, so I'm not sure where to start.

Quote:

What is really a bitch is if you use a non-default template set on your site Cause on module update, it updates the default template in database only.


Not a problem for me -- defaults all the way!

7
Mithrandir
Re: template not automatically recompiled

Check out the class/template.php and class/smarty/smarty.class.php and see what you can figure out.

GL

(the bitching about non-default templates was more of a This-happened-to-me-and-was-annoying thing )

8
phatjew
Re: template not automatically recompiled
  • 2003/11/20 19:53

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Thanks for the advice, everyone.

In the end, I had to pull code from class/template.php, kernel/tplfile.php, and modules/system/admin/modulesadmin/modulesadmin.php.

Below is, I believe, a self-contained template recompiler function. It returns false if the update did not succeed, true otherwise. It can easily be made more generic, by basing it on a module id instead of a specific template, but I didn't want to recompile every template every time, just the one I am using at the moment.

(Note: I used queryF() rather than query() because I need to perform this function in querystring-based pages. This can be considered a minor security issue, I know, but I do not plan to have this code called EVER once the site goes live.)

function recompileTemplate($dirpath,$fileName) {
    Global 
$xoopsDB,$xoopsTpl;
//1. get tpl_id based on filename
    
$sql "SELECT tpl_id FROM ".$xoopsDB->prefix("tplfile").
           
" WHERE tpl_file = '".$fileName."'";
    
$result $xoopsDB->queryF($sql);
    list(
$tpl_id) = $xoopsDB->fetchRow($result);

//2. read file into memory
    
$path XOOPS_ROOT_PATH.'/modules/'.$dirpath.'/templates/'.$fileName;
    
$lines file($path);
    
$filecontents '';
    
$count count($lines);
    for (
$i 0$i $count$i++) {
        
$filecontents .= str_replace("n""rn"str_replace("rn""n"$lines[$i]));
    }
    
//3. update tplsource with new template
    
$sql "UPDATE ".$xoopsDB->prefix("tplsource").
           
" SET tpl_source =".$xoopsDB->quoteString($filecontents).
           
" WHERE tpl_id = ".$tpl_id;
      if (!
$result $xoopsDB->queryF($sql)) {
         return 
false;
    } 
    
//4. recompile template
    
include_once XOOPS_ROOT_PATH."/class/template.php";
    
xoops_template_touch($tpl_id);
    
    return 
true;
}

9
Mithrandir
Re: template not automatically recompiled

How do you use that one?

10
phatjew
Re: template not automatically recompiled
  • 2003/11/21 14:53

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Quote:

MithyT2 wrote:
How do you use that one?


I am writing a reviews module called PJReviews. (I hope to release it soon -- I am adding more admin functionality, converting to templates, and integratng more XOOPS code (xoopsForm in particular) to make it easier for others to use and modify.)

Anyway, in my module's index.php page, I have an if/elseif block to determine what to display, like the front page, a full review, or the results of a search. Inside each of these if{} block, I have code like this:

recompileTemplate('pjreviews','pjreviews_index.html');
recompileTemplate('pjreviews','pjreviews_searchbox.html');
$xoopsOption['template_main'] = 'pjreviews_index.html';


Where 'pjreviews_searchbox.html' is a template file included within 'pjreviews_index.html'

When I am ready to go live, I will simply comment out the "recompileTemplate" lines. However, right now I am constantly making changes to templates, and it saves me tons of time to have them automatically reloaded from the file into the database (the hard part) and recompiled (the easy part). Note that I do not have to explicity clear the cache every time, because the xoops_template_touch() function does that for me.

Hope that answers your question.

Login

Who's Online

241 user(s) are online (158 user(s) are browsing Support Forums)


Members: 0


Guests: 241


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits