jeffer Posted January 9, 2015 Share Posted January 9, 2015 Hello I have a customized WHMCS template which displays all knowledgebase articles on 1 page, but it is using the following code in knowledgebasecat.tpl. {foreach from=$kbarticles item=kbarticle} <div class="AccordionPanel"> <div class="AccordionPanelTab">{$kbarticle.title}</div> <div class="AccordionPanelContent"> <div class="box1"> <p><span class=" green"><b>{$kbarticle.title}</b></span></p> <div class="spacer2"></div> <p>{$kbarticle.article}</p> </div> </div> </div> {foreachelse} This is working fine, but {$kbarticle.article} is not displaying the full content, it skips all the HTML. {$kbarticle.text} actually does do that, but does not work within the foreach code above. This will only work in knowledgebasearticle.tpl Any idea how I can get the full HTML output of an article or make .text work in that foreach? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 9, 2015 Share Posted January 9, 2015 is the page you are using totally custom or the default knowledgebase.php page? 0 Quote Link to comment Share on other sites More sharing options...
jeffer Posted January 10, 2015 Author Share Posted January 10, 2015 is the page you are using totally custom or the default knowledgebase.php page? Hello, it's a bit half. The template is from the original template, knowledgebasecat.tpl, but only HTML has been modified to fit the design. And the foreach has been added, that's the only difference in this case. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 10, 2015 Share Posted January 10, 2015 Then if you are using the default .php file first try to {debug} the .tpl to ensure that the variable that you are looking for isn't there. If it isn't you should create a custom .php file where have to retreive this variable, $smarty->assign("yourvariable", $yourvalue); and then {include_php} it on top of your .tpl so that you can use it on .tpl. If necessary you can also overwrite an existing and buggy value with your one. 0 Quote Link to comment Share on other sites More sharing options...
jeffer Posted January 10, 2015 Author Share Posted January 10, 2015 Then if you are using the default .php file first try to {debug} the .tpl to ensure that the variable that you are looking for isn't there. If it isn't you should create a custom .php file where have to retreive this variable, $smarty->assign("yourvariable", $yourvalue); and then {include_php} it on top of your .tpl so that you can use it on .tpl. If necessary you can also overwrite an existing and buggy value with your one. I actually did try to use {debug}, but it didn't output anything and I don't know why. Thank you for your information, though I'm not sure how to fix this now. If I will use $smarty->assign("....., what will 'yourvariable' then be? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 10, 2015 Share Posted January 10, 2015 Ensure that you haven't placed {debug} inside an {if} or {foreach} that doesn't trigger it. Anyway in pseudo-code you should make something like this. Create your custom .php file. // Get article from database $result = SELECT article FROM tblknowledgebasearticles WHERE id = $id // Assign the value of article from database to smarty $smarty->assign("article", $result["article"]); Now open your .tpl. {include_php '/path/to/your/php'} // Now {$article} contains the article <b>This is the article: {$article} Read it!</b> 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 10, 2015 Share Posted January 10, 2015 open knowledgebasecat.tpl with any editor, and place the following code at the first line of it: {php} $select_articles = full_query("SELECT `tblknowledgebase`.*,`tblknowledgebaselinks`.* FROM `tblknowledgebase`,`tblknowledgebaselinks` WHERE `tblknowledgebaselinks`.`categoryid`='{$this->_tpl_vars['catid']}' AND `tblknowledgebaselinks`.`articleid`=`tblknowledgebase`.`id`"); while ($articles = mysql_fetch_assoc($select_articles)){ $articleText[$articles['id']] = stripslashes($articles['article']); } foreach($this->_tpl_vars['kbarticles'] as $key => $article){ $this->_tpl_vars['kbarticles'][$key]['text'] = $articleText[$article['id']]; } {/php} after that you can use {$kbarticle.text} to output the whole content with it's HTML tags. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 10, 2015 Share Posted January 10, 2015 Exactly but I suggest you not to use {php} tag in Smarty template because of this: {php} tags are deprecated from Smarty, and should not be used. Put your PHP logic in PHP scripts or plugin functions instead. So put that code in a php file to avoid further problems. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 11, 2015 Share Posted January 11, 2015 @kian smarty say the same about {include_php} {include_php} is deprecated from Smarty, use registered plugins to properly insulate presentation from the application code. As of Smarty 3.1 the {include_php} tags are only available from WHMCS v5.3.11 support {php} and use it inside templates. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 11, 2015 Share Posted January 11, 2015 Uh yep true! Well at this point it's just a style preference. I pref no php in tpl anyway. 0 Quote Link to comment 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.