jack2006 Posted May 6, 2009 Share Posted May 6, 2009 I've tried to have this answered on the smarty.net forum and digitalpoint, in the smarty forum i simply did not get an answer (cuz maybe it's to stupid to answer), the other onese did not solve the problem. I have had a lancer write a script for me. He used smarty for it. Everything works fine but i don't know how to ad a link to another page of the site. He tells me that that functionality is not available and if i want it he will charge me for making it. (he has to create a module) After digging around i have managed to figure out how to create a page in the system, I can even call it up within another page, but i don't know how to link to it so it displays independently. (It's an about us page and the link would be in the footer). Here is what i have done so far: I have created both a file called about.php and placed it where all my other php page files are. That file contains the following code <?php $obj['smarty']->assign('file_inc', 'about.tpl'); ?> I then created a file called about.tpl placed it in the templates folder and did my templating in that file. I also included about.tpl in the database alongside the other pages listed in it. Ok so now I would like to link to that file so it displays as domain.com/about.html (or php or anything really). Here is my footer <div id="footer"> <p>{$params.copyr} | <a href="mailto:{$params.email}">{$_lang.Contact_us}</a> | <a href="mailto:bug@domain.com">Report Bugs</a></p> <p><a href="">What is domain.com</a></p> The part i don't know how to do is what to put in here: <p><a href="????????">What is domain.com</a></p> If i just place <a href="http://www.domain.com/about.php"> or any variation thereof (even include path to the file) and i click the link i am not taken to that page but left on my main page. (as if it was a 404 error or something). I've been at this problem for a week and i'm about to go ape$%$% please someone help? Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/ Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Does your about.php page include the Smarty class? If so, then do this: <?php // include Smarty here $obj['smarty']->assign('url', 'URL_HERE'); In tpl <p><a href="{$url}">What is domain.com</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827678 Share on other sites More sharing options...
JonnoTheDev Posted May 6, 2009 Share Posted May 6, 2009 You will not get a solution as the coder has used his own structure for your website. I'm guessing this is done using an MVC (model, view, controller) pattern. You may need to add a new class method or subclass for this page. My advice would be to copy an existing page. What do the urls look like for other pages? They maybe parameter based. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827685 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 You will not get a solution as the coder has used his own structure for your website. I'm guessing this is done using an MVC (model, view, controller) pattern. You may need to add a new class method or subclass for this page. My advice would be to copy an existing page. What do the urls look like for other pages? They maybe parameter based. Not necessarily. Smarty systems aren't too different from one another, shockingly. It really doesn't matter what structure the coder used. Adding a variable is as simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827693 Share on other sites More sharing options...
JonnoTheDev Posted May 6, 2009 Share Posted May 6, 2009 Not necessarily. Smarty systems aren't too different from one another, shockingly. It really doesn't matter what structure the coder used. Adding a variable is as simple as that. That isn't the problem. Assigning a variable to a template is easy yes. He is asking what the url is to his new page for a link in his footer. Read the post. If he uses /about.php then the page does not display correctly. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827702 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 There are $_SERVER vars. It would help to understand the system more, but for something like this, it's not needed. He can hard code the link if he wanted. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827718 Share on other sites More sharing options...
jack2006 Posted May 6, 2009 Author Share Posted May 6, 2009 Ken2k7 So here what i have done as you suggested: about.php <?php $obj['smarty']->assign('file_inc', 'about.tpl'); $obj['smarty']->assign('url', '/about.php'); ?> In tpl <p><a href="{$url}">What is domain.com</a></p> Unfortunately that did not work. I've located the following code that talks about url's and all maybe that will help: // Get the document $document = $obj['tree']->get_item($obj['url']->link); if (!$document) { header("HTTP/1.1 404"); $obj['smarty']->assign('file_inc', 'error404.tpl'); $obj['smarty']->display('error404.tpl'); exit; } if ( $document['isdir'] || $document['pid']!=0 ) { if ( $document['pid']!=0 ) { $parent = $obj['tree']->get_item($document['pid']); } else { $parent = $document; } $parent['items'] = $obj['tree']->get_childrens($parent['id']); $obj['smarty']->assign('document_parent', $parent); } //$path = $obj['tree']->get_path($document['id']); $path = array(); $path2 = $path; $path2[] = $document; $document_not_found = 0; if($document['public']) { foreach($handles as $h) { if((int)$h['id'] == (int)$document['handle']) { require($CFG['path']['process'] . $h['script']); } } } else { header("Location: /"); exit(); } // Checking is not whether to go to the first child element if($document['is_gochild']) { $childs = $obj['tree']->get_childrens($document['id']); if (is_array($childs)) { header("Location: /" . $childs[0]['alias'] . ".html"); exit; } } // Smarty pass some of the variables $obj['smarty']->assign('var', $VAR); $obj['smarty']->assign('cfg', $CFG); $obj['smarty']->assign('handles', $handles); $obj['smarty']->assign('document', $document); $obj['smarty']->assign('path', $path); $obj['smarty']->assign('path2', $path2); $obj['smarty']->assign('url', $obj['url']->url); Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827727 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Hmm.. can you post up a template that has a variable in it? Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827732 Share on other sites More sharing options...
jack2006 Posted May 6, 2009 Author Share Posted May 6, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>{$params.title}</title> <link rel="stylesheet" href="/images/css/style.css" type="text/css" /> <!--[if lt IE 8]><link rel="stylesheet" href="/images/css/ie.css" type="text/css" /><![endif]--> <!--[if lt IE 7]><link rel="stylesheet" href="/images/css/ie6.css" type="text/css" /><![endif]--> <script src="/javascripts/main.js" type="text/javascript"></script> </head> <body class="mainpage"> <div id="header"> <div class="inner"> <h1 class="logo">{$params.sitename} <small>{$params.site_description}</small></h1> <div align="right"> {foreach from=$_PL item=_lname key=_lalias} {if $smarty.session.lang!=$_lalias}<a href="?lang={$_lalias}">{$_lname}</a>{else}{$_lname}{/if} {/foreach} </div> </div> </div> <div id="content"> <form action="/work/enter" class="create-workt" id="new_room" method="post"> <input type="hidden" name="room" value="{$work_alias}" /> <fieldset> <div class="name"> {if $smarty.get.pe} <center><b>{$_lang.Password_is_wrong}</b></center><br /> {/if} <div class="bor"> <input class="name enter-name" id="user_name" maxlength="20" name="username" size="20" type="text" value="{$_lang.Enter_your_name}" onfocus="MchName(this,true,'{$_lang.Enter_your_name}');" onblur="MchName(this,false,'{$_lang.Enter_your_name}');" style="color:#C0C2C5"/> {if $have_pass} <br /> <input class="name enter-name" id="user_name" maxlength="20" name="password" size="20" type="text" value="{$_lang.Password}" onfocus="MchName(this,true,'{$_lang.Password}');" onblur="MchName(this,false,'{$_lang.Password}');" style="color:#C0C2C5"/> {/if} </div> </div> <div align="center"><input type="image" src="/images/design/forms/{$smarty.session.lang}/enter.png" class="btn enter-chat-logic"/></div> </fieldset> </form> </div> <div id="footer"> <p>{$params.copyr} | <a href="mailto:{$params.email}">{$_lang.Contact_us}</a> | <a href="mailto:bug@domain.com">Report Bugs</a> | <a href="/pda/">Mobile Version</a></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827740 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Oh he has arrays. Would it be okay if you just inline it? <p><a href="http://mydomain.com/about.php">What is domain.com</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827763 Share on other sites More sharing options...
jack2006 Posted May 6, 2009 Author Share Posted May 6, 2009 Normally it would but it just gives me a 404 error. In the database there is a table called handles where all the php files and their tpl files are listed I also added the about.php and tpl files there, it has an id # of 47 Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-827788 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Why does it give you an error? The reason I asked is because it would be more troublesome to investigate the arrays feature. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-828141 Share on other sites More sharing options...
jack2006 Posted May 7, 2009 Author Share Posted May 7, 2009 It would be awesome if i knew why it gave me the error. If for example i place test.html in the root directory, i can't navigate to it as it gives me a 404. It looks as if there is some blocking mechanism. Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-828217 Share on other sites More sharing options...
black.horizons Posted May 19, 2009 Share Posted May 19, 2009 put {debug} at the top of your .tpl page and paste in what the popup window says...(if you dont get a popup disable your popup blocker!!) Quote Link to comment https://forums.phpfreaks.com/topic/157107-smarty-linking-question-nobody-seems-to-know-the-answer-to/#findComment-837118 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.