Jump to content

Making {$kbarticle.text} work in other file


jeffer

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated