PHP - Why Smarty Won't Find My Template File?
Why smarty won't find my template file?
Fatal error: Uncaught --> Smarty: Unable to load template file 'test.tpl' <-- thrown in C:\xampp\htdocs\testing\includes\smarty\sysplugins\smarty_internal_templatebase.php on line 129also did testinstall $smarty->testInstall(); Smarty Installation test... Testing template directory... C:\xampp\htdocs\testing\templates\frontend\default\tpl is OK. Testing compile directory... C:\xampp\htdocs\testing\templates_c\frontend is OK. Testing plugins directory... C:\xampp\htdocs\testing\includes\smarty\plugins is OK. Testing cache directory... C:\xampp\htdocs\testing\cache is OK. Testing configs directory... C:\xampp\htdocs\testing\configs is OK. Testing sysplugin files... ... OK Testing plugin files... ... OK Tests complete.And get template dir var_dump($smarty->getTemplateDir());array(1) { [0]=> string(55) "C:/xampp/htdocs/testing/templates/frontend/default/tpl\" } File schema htdocs -- testing -- incluses -- smarty plugins sysplugins Smarty.class.php SmartyBC.class.php -- configs configs.php -- db connect.php db.php -- configs -- cache -- templates -- frontend -- default -- css -- mages -- js -- tpl test.tpl -- backend -- templates_c -- frontend index.phpindex.php <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('display_startup_errors', TRUE); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); ob_start(); session_start(); require 'includes/smarty/Smarty.class.php'; require 'includes/db/db.php'; require 'includes/configs/configs.php'; $page = isset($_GET['do']) ? $_GET['do'] : ''; switch($page){ case 'home'; include 'pages/home.php'; break; default: include 'pages/test.php'; break; } ob_flush(); ?>configs.php <?php $smarty = new Smarty(); $smarty->compile_check = true; $smarty->debugging = false; $smarty->cache = 1; $smarty->setTemplateDir('C:/xampp/htdocs/testing/templates/frontend/default/tpl'); $smarty->setCompileDir('C:/xampp/htdocs/testing/templates_c/frontend/default'); $smarty->setCacheDir('C:/xampp/htdocs/testing/cache'); $smarty->setConfigDir('C:/xampp/htdocs/testing/configs'); ?>test.php <?php //$success = 'Success Message'; //$error = 'Error Message'; $errors[] = 'Error one'; $errors[] = 'Error two'; $smarty = new Smarty; //$smarty->assign('success', $success); //$smarty->assign('error', $error); $smarty->assign('errors', $errors); $smarty->display('test.tpl'); ?>test.tpl {if !empty($errors)} <div id="errors"> {section name=i loop=$errors} {$errors[i]}<br /> {/section} </div> {/if} Similar Tutorialshey guys i have this code to grab info from database in my inv.php file
$dbConn = new DBConnection(); $i = new dbHandler($dbConn, 'inventory'); $inv = array(); $sel=mysql_query("select * from inventory"); while($row=mysql_fetch_array($sel)) { $inv[] = $row; } $smarty->assign('inventory', $inv); // Finally, display the actual page $smarty->display('InvViewAdd.tpl');How to i make it show the info on my InvViewAdd .tpl page? also if i put $inv = $i->showInv(); So why would one use a php template engine like smarty, other than to seperate the code from html? Is this method preffered for creating larger web applications with php?
Ok so i have made the page to load the data and i have my tpl file loading i just can't figure out for the life of me why it is not displaying correctly.
what it is displaying
php for the page
<?php if($Auth->isLogged()) { $aid = $Auth->loggedAid(); $limit = 10; //grab available PTC links from db output in json $db->select('*', 'ptc', 'active = 1'); if($db->returned_rows >= 1) { $username = $Auth->loggedUsername(); $time = time(); //$row = $db->fetch_assoc_all(); $smarty->assign('row', $db->fetch_assoc()); $smarty->assign('username', $username); $smarty->assign('time', $time); } else { //set var not to display ptc ads $smarty->assign("row", "No PTC are available"); } } $smarty->display('ptc_view.tpl'); ?>tpl file <!-- START content-container --> <section id="content-container" class="clearfix"> <div id="main-wrap" class="clearfix"> <div class="page_content"> <table class="table table-hover"> <tr> <th>Ad Link</th> <th>Earnings | Points</th> <th>Times Completed</th> <th>Total Visits</th> <th>Date Added</th> </tr> {foreach key=pid item=ri from=$row} <tr> <td><a href="Pages/ptcview/{$ri[0]}">{$ri[1]}</a><br/>{$ri[3]}</td> <td>{$ri[5]} | {$ri[6]} pts</td> <td>{$ri[8]}</td> <td>{$ri[7]}</td> <td>{$ri[13]}</td> </tr> {foreachelse} <tr> <td colspan="5">Sorry there are no PTC ads available right now</td> </tr> {/foreach}can someone please show me where i have gone wrong? BTW the db table does exist and there is 1 record in it. OK guys please bear with me as this is going to be a little long post. Thanks in advanced for all the help i can get. Ed I am sorry i am a noob on all this. Now on to the problem. I have on my server the aMember script installed and as some of you guys know it works with CSS and Smarty Template Engine. the Signup page is been constructed by three files .. Signup.php which in turn displays the signup.html page in my templates folder. Signup.html load or includes header.html from the same folder. Now on the header.html i put the code of the <head> tag like always <script src ...> loading all the JS libraries. But the libraries actually do not get loaded. I am uploading the three files here in a ZIP file so you guys can have a look at them and try to tell me what am i doing wrong and you guys can point me in the right direction. On the server side i am using Centos 5.5 with apache and php 5 and mySQL server. The html folder is owned not by apache but by another group. Inside the html folder the normal folders including the SMARTY folder templates and templates_c (for temporary cache files) The signup.php page is on the root folder calling the signup.html from templates and this one includes the header at the same time. All the page are CHMOD 644 and the JS are residing in a root folder named JS where all the .js files are. All the .js files are CHMOD 644 as well. Please help me ASAP. Thanks Ed This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355225.0 How can i find out parent (including) file of included file? Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included? I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me? I have short urls on the same page that this javascript code is on. the problem is that the code now can't find the poll.php. I have tried the full path and full url to the poll.php, but the code still outputs file not found. how to get this code working?
$.post('poll.php', $(this).serialize(), function(data, status){ I have a page with links to images. Currently the images open in a blank browser window, and I think this is too plain. I don't want to create an HTML file for each image. I want to have an 'image display php file' - img_temp.php. Along with the reference to the image file, in the link, I want to also be able to send a <title> to the template file. I think the code below shows kinda' what I'm trying to do, and also shows that I don't quite have a grasp on how to do it. Any tips would be appreciated. Index Page (index.php) Code: [Select] <html> <head> <title>Gallery Links</title> </head> <body> <!-- This is the page with the links to the images --> <ul> <li><a href="img_temp.php?file=images/01.jpg<?php ?title = "This is image 1"?>">Image 01</a></li> </ul> </body> </html> Image Display Template (img_temp.php) Code: [Select] <html> <head> <title><?php echo $title ?></title> </head> <body> <!-- This is the page that displays the sent image and displays the appropriate doc title --> <?php //Output the image $file echo $file; ?> </body> </html> Hi, Everyone! I have an issue and I'm not even sure if it can be done with PHP, but even this info would help me (to stop looking for an answer). I need to populate a (MySQL) database with stuff which is now written in a (HTML formatted) file. Here are my options: 1. Copy/paste each single field via PHPMyAdmin . 2. Write a little script to extract the necessary parts of text from these files to create a CSV-like content which I would then easily INSERT into the db. Example The files look like this: Code: [Select] <!-- SEPARATOR (same throughout the file(s) --> <tr><td> <div style="something"><img src="img/what_i_need_to_extract_1.png"></div> </td><td> <div style="something else"><b>What I need to extract 2</b></div> <div style="something else">What I need to extract 3</div> </td></tr> <!-- SEPARATOR (same throughout the file(s) --> etc ... and it goes like... 100 times in each file in the same standard pattern with the "What I need to extract" parts being completely different each time. Since it's possible to tell when each part required for extraction begins and ends, I would expect the script to look for these key-points (according to the example, it would be: img/ to "></d then "><b> to </b>< and else"> to </div>) and return a result like this (acc. to the example): ('what_i_need_to_extract_1.png', 'What I need to extract 2', 'What I need to extract 3'), (and so on...). Is it possible? Is there a function/option/way to look for a start/end-point like this and fetch the part between these two set points? If so - how? Any help would be appreciated, I'm not expecting a full code, obviously, just a point to the right direction or where to look at would be nice. Thanks in advance. Is it pasible to find all occurrences of strings "North" and "North-East" in some txt file and save number of occurrences in some variables?? Say I have... Code: [Select] <? echo("do something"); include("include_file.php"); echo("do something else"); ?> include_file.php Code: [Select] <? $a_$string = "a string"; echo($a_string); ?> I have put an error in the include_file.php an extra $ in the variable name. The first script would kick up an error that there is a problem with file include_file.php as line 3 or what ever the line may be. How can I have it so I can choose what the error message is, say a cryptic code and the line number without having the file names show as this is showing up my hidden includes folder and the file name which means that someone may try to visit this page alone and this can cause security issues. Adding in extra lines to every file to see if it is being use correctly a bit like sessions is not an option although I have looked at it as I have houndreds of files to alter in this case. I have just tried this instead of the top script but I does not show the secret code on error Code: [Select] <? echo("top"); @include("dummy.php") or die("secreterrorcode123"); echo("bottom"); ?> I wanted to replace a strings in a large text file .. what would be the fastest way ?! e.g the text file contains .. INSERT INTO `subjects` VALUES (1, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (2, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (3, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (4, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (5, 'some text here', 'some text here', 'some text here'); I wanted to replace the string " VALUES (1, " with "VALUES (" in each line .. I'm new in PHP so any response would be much appreciated .. thanks Seems this should be easy, but I'm not finding the solution. Functions like scandir, readdir, and glob that I've been looking at all seem to need me to actually know more about my directory path than I can ahead of time. Here's what I want to do: 1. expand a .tar file (consists of directory, subdirectories, files, and is variable) that I've uploaded to the server 2. look through that expanded directory for a subdirectory named ".pn" -- (note that all my .tar files will have this folder deep in several subdirectories that will be variable in number and have different names depending on the original .tar file) 3. copy the entire contents of the .pn folder to another folder already on my server The hosting company, no doubt, has likely blocked some of the functions I'll need as well, but if someone can point me in the right direction to start, it would be greatly appreciated. Thanks! Satre This is probably an easy one, but I can't figure it out and it's pretty much not searchable. on a linux-machine i have installed filezilla the filezilla runs pretty well and all is ok. now i need to have the passwd that i have stored years ago. The passprhase is stored in a plain in a file called sitemanager.xmlfile I want to find that file and open it with a terminal command. find . -name *.sitemanagerwell i thought that this will return the file I'm looking for. Now how do I open it automatically, without typing the name? find . -name *sitemanager.xm | openThis doesn't work. It says it doesn't found the open command. question: why it does not work on opensuse? should i use any other command - eg the following: find . -name *xyz | xargs openor find . -name *sitemanager.xml | xargs openor find . -name *.xyz -exec open {} \;and find . -name *.xyz -exec open {} \; .any and all help will be greatly appreciate again: what is wanted and needet is to find out the passphrase in the filezilla-configuration Hello all; My site is at: http://www.designtoprint.com The problem is that it looks great in everything but Internet Explorer. In I.E., it's utterly broken. I think this has a lot to do with the fact that the former developer who worked on it did everything in Smarty. I'm wondering if there's a way to automate the process of recombining all the Smarty pages back into normal .php files. Or barring that, if any of you smarter-than-me people know off the top of your heads why my site is breaking in I.E., but nothing else. Thanks! Kyle Hello, I am trying to take a calendar script and use it on my site that uses Smarty templates. I have gotten all of it to work minus one spot! I am having trouble trying to get the code below to output what I want in Smarty... I have tried many things but to no avail! Any help would be appreciated! Thanks!! Obviously I want the html output from these PHP calls but I cant figure it out! Thanks for your help! for($i=0; $i< $total_rows; $i++) { for($j=0; $j<7;$j++) { $day++; if($day>0 && $day<=$total_days_of_current_month) { //YYYY-MM-DD date format $date_form = "$current_year/$current_month/$day"; //echo $date_form_good = '<td'; //check if the date is today if($date_form == $today) { $class_today = ' class="today"'; } //check if any event stored for the date if(array_key_exists($day,$events)) { //adding the date_has_event class to the <td> and close it $event_today = ' class="date_has_event"> '.$day; //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul> $event_title = '<div class="events"><ul>'.$events[$day].'</ul></div>'; } else { //if there is not event on that date then just close the <td> tag $no_event = '> '.$day; } $close_tag= "</td>"; } else { //showing empty cells in the first and last row $mts = '<td class="padding"> </td>'; } } $close_row = "</tr><tr>"; } Hi there, I wonder if anyone can help me. I'm trying to install smarty. The problem I'm having is in choosing the correct path directory for- require('/usr/local/lib/php/Smarty/Smarty.class.php'); Granted I am relatively new to coding. I've tried using- <?php echo $_SERVER['DOCUMENT_ROOT']; ?> which returns- /usr/local/apache/htdocs I think the problem is in understanding what my local directory is. In my ftp program, the first folder looks like this firstfolder/ public_html/ ( < I've installed smarty in this one) DO_NOT_UPLOAD_HERE.txt When I run a test file index.php, I get the following error- Warning: require() [function.require]: open_basedir restriction in effect. File(/usr/local/public_html/lib/php/Smarty/Smarty.class.php) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a4808331/public_html/index.php on line 4 What I've put in my index.php file so far which I'm sure is wrong is- require('/usr/local/public_html/lib/php/Smarty/Smarty.class.php'); If you need more info I'd be happy to supply. Thanks in advance for your help. I am using X cart and I have tried add function that hide price until customers log in. so I added following codes to my files with notepad but I am keep getting smarty errors Error: Smarty error: [in customer/main/products_t.tpl line 161]: syntax error: 'if' statement requires arguments (Smarty_Compiler.class.php, line 1270) in /home1/lemielfa/public_html/include/lib/smarty/Smarty.class.php on line 1092 Here's Smarty.class.php line 1092 ------------------------------------------------------------------------------------------------------------------------------------- * @param string $error_msg * @param integer $error_type */ function trigger_error($error_msg, $error_type = E_USER_WARNING) { (line1092----->)trigger_error("Smarty error: $error_msg", $error_type); } /** * executes & displays the template results -------------------------------------------------------------------------------------------------------------------------------- This was my first time adding some code to my web, I hope I didn't screw up that much...... Thank You David ---------------------------------------------------------------------------------------- Following Code ADDED /b] 1. Apply following SQL statements either from your cart admin/patch area or myphpadmin. This will place 2 controls in General Settings / General options in Common options. The first one will allow you to turn this mod on/off Code: INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices', 'Hide prices for non-logged in customers (this will also hide quantity box, "buy now" and "add to cart" buttons)', 'N', 'General', 75, 'checkbox', 'N', '', ''); INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices_message', 'Show this optional message if the option "Hide prices" is enabled', 'You need to login in order to see prices and place orders.', 'General', 76, 'text', '', '', ''); 2. Add to init.php at the end of the file just before PHP Code: # # WARNING ! # Please ensure that you have no whitespaces / empty lines below this message. # Adding a whitespace or an empty line below this line will cause a PHP error. # this PHP Code: # added by CFL Systems for hide prices if customer not logged in $smarty->assign("cflsys_hide_prices",$config['General']['cflsys_hide_prices']); $smarty->assign("cflsys_hide_prices_message",$config['General']['cflsys_hide_prices_message']); # added by CFL Systems for hide prices if customer not logged in 3. In skin1/customer/main/products.tpl find Code: {if $config.Appearance.products_per_row && ($featured eq "Y" || $config.Appearance.featured_only_multicolumn eq "N")} {include file="customer/main/products_t.tpl"} {else} {include file="customer/main/products_list.tpl"} {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} {if $cflsys_hide_prices_message ne ""} <div style="color: red; margin: 5px 0; padding: 5px 5px 5px 10px; border: 1px solid #cccccc;">{$cflsys_hide_prices_message}</div> {/if} {/if} {* added by CFL Systems to hide prices if customer not logged in *} 4. In skin1/customer/main/product.tpl (skin1/customer/main/product_details.tpl for 4.3.x, code may be slightly different) find this Code: <tr> <td class="property-name product-price">{$lng.lbl_price}:</td> <td class="property-value"> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {if $product.forsale ne "B"} <tr> <td colspan="2"> {include file="customer/main/product_prices.tpl"} </td> </tr> {/if}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: <tr> <td class="property-name product-input"> {$lng.lbl_quantity}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> {if $cflsys_hide_prices_message ne ""} {$cflsys_hide_prices_message} {else} {/if} </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {/if} </table> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {if $product.appearance.buy_now_buttons_enabled}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: </form>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 5. In skin1/customer/main/products_list.tpl find Code: {if $product.product_type eq "C"} {include file="customer/buttons/details.tpl" href=$url} {else}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {/if} </div> <div class="clearing"></div>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 6. In skin1/customer/main/products_t.tpl find Code: <tr> {foreach from=$row item=product} {if $product} <td class="product-cell product-cell-price"> {if $product.product_type ne "C"} {if $active_modules.Subscriptions ne "" && $product.catalogprice} and before add Code: {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find at the end of the file Code: {/foreach} </table> {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} |