1
astrix
Really Strange Smarty Problem
  • 2004/8/17 9:40

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16


I don't know if I'm missing anything, but for some reason, Smarty absolutely refuses to print my variable!

This is my php code:

<?php 
require('../../mainfile.php'); 

if ( !empty(
$HTTP_POST_VARS['action']) ) {

    
$do $HTTP_POST_VARS['action'];

} elseif (!empty(
$HTTP_GET_VARS['action'])) {

    
$do $HTTP_GET_VARS['action'];

}

// Our table of editions
$table $xoopsDB->prefix('cr_editions');

// Fetch all our editions
$result $xoopsDB->query("SELECT * FROM $table");
if (
$xoopsDB->getRowsNum($result) >= 1) {
  
$editions = array();
  while (
$rows $xoopsDB->fetchArray($result)) 
      
array_push($editions$rows['edition']);
}



if(
$do=="browse") {
    
// We must always set our main template before including the header 
    
$xoopsOption['template_main'] = 'nav_browser.html'
    
    
// Include the page header 
    
require(XOOPS_ROOT_PATH.'/header.php'); 
    
    
$xoopsTpl->assign('edition'$editions[0]);
    
// Include the page footer 
    
require(XOOPS_ROOT_PATH.'/footer.php'); 
    
} elseif(
$do=="search") {

    
$xoopsOption['template_main'] = 'nav_search.html';
    
    require(
XOOPS_ROOT_PATH.'/header.php');
    
    
    
    require(
XOOPS_ROOT_PATH.'/footer.php');
    
}

?>


Now, here's my really simple test template:

<p><{$edition}></p>


it doesn't print the variable $edition! It does print the <p></p> though. I also turned on Smarty debug to check the variable, and the variable $edition does in fact have the value I want it to print. Now here's where it gets even stranger:

if, instead of printing $edition, i try to print the variable $table, which is just the table returned by the xoopsDB call, it works (IE I replace the line
$xoopsTpl->assign('edition'$editions[0]);
with
$xoopsTpl->assign('table'$table);

and change the template var accordingly, it prints the table name. Am I missing something really obvious? I've been trying for hours, and I'm at my wit's end :(

2
Mustang
Re: Really Strange Smarty Problem
  • 2004/8/17 10:36

  • Mustang

  • Just popping in

  • Posts: 17

  • Since: 2004/4/15


I don't know but... maybe there aren't any rows in the table $table? Too ovbious, I know, but just in case.

3
astrix
Re: Really Strange Smarty Problem
  • 2004/8/17 11:11

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16


Well I have only 1 row in that table right now as a test. I mean, since the smarty debug output *shows* that $edition var in the template has a value that is correctly matched with the value in the table, it's fetching a non-empty table row. Bugs seem to love me. I first had a problem setting up my site with wrapping XOOPS around old html where I had to make a separate script to change the table structure to fix the new css stuff in XOOPS and the deprecated table tags used in the old html. Now this :( . Well, I appreciate your help, I'm going to sleep a bit and come back and try to tackle it. I really hope it's something I'm missing.


4
astrix
Re: Really Strange Smarty Problem
  • 2004/8/17 13:25

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16


Some more testing and I am finding something really strange:

the template won't display any variable unless it's named $table.

I can have any variable in the php code but as long as I do

xoopsTpl->assign('table', $any_var_here) it will work fine. The moment I change the 'table' to anything else and change it to the same in the template, it suddenly doesn't display the variable, although in the smarty debug it shows the variable having the correct value (and is non-empty).

5
astrix
Re: Really Strange Smarty Problem
  • 2004/8/17 14:18

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16


Hmm, ok I think I may have found the problem, (I guess this is my fault, not sufficiently understanding the module system).

It seems XOOPS compiles the module's templates upon module install, which probably accounts for the weird behavior of my template variables after I uploaded a new template and didn't reinstall the module (it was probably still using the old cached template).

However, I *assumed* that merely uploading a new template and then updating the module should clear the template cache . This doesn't seem to be the case.

The only effective way to have the template work correctly is to clear the template cache.

Is there no way to easily have it not cache the template at all? I really don't want to have to manually delete the cache file everytime.

6
astrix
Re: Really Strange Smarty Problem
  • 2004/8/17 14:43

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16




7
Dave_L
Re: Really Strange Smarty Problem
  • 2004/8/17 14:54

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


When working on templates, I enable "Update module template .html files from themes/your theme/templates directory?" in System Admin >> Preferences >> General Settings. That forces templates to be recompiled whenever I change them.

If I want to verify that my template changes are processed, I'll put some unique text at the top of the template, such as "edited at 1126 Tuesday".

8
astrix
Re: Really Strange Smarty Problem
  • 2004/8/17 15:00

  • astrix

  • Just popping in

  • Posts: 30

  • Since: 2004/8/16


Ah ok, thanks for the tip. I actually stared at that option for a few seconds, but I guess the meaning didn't register correctly. I assumed it meant update the module's .html only when the theme's .html is updated. I don't plan on making any changes to themes, just the module templates, so I assumed it wouldn't recache an updated template if I didn't change a theme template.

However, I found that just using the built-in template manager worked quite nicely, if I upload the new template through that, it seems to clear the cache file for the particular template I uploaded.

Login

Who's Online

249 user(s) are online (173 user(s) are browsing Support Forums)


Members: 0


Guests: 249


more...

Donat-O-Meter

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

Latest GitHub Commits