cdeese8 Posted November 28, 2017 Share Posted November 28, 2017 Using WHMCS 7.1.1 and six template. WHMCS Admin Support Knowledgebase Add Article I've tried a few things but nothing works. I even have {debug} enabled on knowledgebasearticle.tpl I'll add below code to an article and click save and open new private tab, while logged into demo user. Quote {if $loggedin}<p>Hey {$clientsdetails.firstname},</p>{/if} {if $loggedin}<p>Hey {$loggedinuser.firstname},</p>{/if} Any suggestions? Link to comment Share on other sites More sharing options...
brian! Posted November 30, 2017 Share Posted November 30, 2017 if you're just trying to add Smarty code to an article to show the Smarty code to the user, e.g with no functionality, that would work... i've tested this in both v7.1.2 and v7.4.1 (don't have a 7.1.1. dev). if you're trying to add the code to the template to personalise the article, that would work too... 1 Link to comment Share on other sites More sharing options...
cdeese8 Posted November 30, 2017 Author Share Posted November 30, 2017 (edited) @brian! - thanks for reply! You now what, I forgot to ask at very end, "How do I display Smarty code on specific articles? (not .tpl files)"... it was late and I was all burned up. Yeaaa, the .tpl files have no problem displaying the smarty snippets, but for some reason, when I past smarty snippets into knowledgebase articles, in the admin area, they don't display. It's just plain text that get's printed. You too noticed this? domain.tld/supportkb.php?action=edit&id=420 It looked like, in your screenshots you have similar results as me. 1st screenshot = smarty inside articles created in admin will not display 2nd screenshot = smarty snippet added to .tpl will display Perhaps I'm confusing myself.... hahaha Edited November 30, 2017 by cdeese8 more clarity Link to comment Share on other sites More sharing options...
brian! Posted December 1, 2017 Share Posted December 1, 2017 On 11/30/2017 at 19:07, cdeese8 said: Yeaaa, the .tpl files have no problem displaying the smarty snippets, but for some reason, when I past smarty snippets into knowledgebase articles, in the admin area, they don't display. It's just plain text that get's printed. aahhh - you want to be able to add Smarty code into selected knowledgebase article(s) AND make the code work as it would in the template. On 11/30/2017 at 19:07, cdeese8 said: You too noticed this? yes, but I hadn't realised you were trying to get the code to work, I just assumed these were articles you wanted to add Smarty code to only as viewable text.... therefore, unless you tell the template what you have in mind, it will just do as coded and display the code as text. there are a number of solutions, depending on how far down this road you want to go... 1. let's say you've added "Hey" to the beginning of the article(s) you want to personalise... with a template tweak you could search for that and personalise it... {if $kbarticle.text|strpos:'Hey'===0} {$kbarticle.text|replace:'Hey':"Hey `$clientsdetails.firstname`,"} {else} {$kbarticle.text} {/if} 2. another option would be to make your own tags in the article code - that removes the need for the {if} statement and you can just use a series of replaces instead... {$kbarticle.text|replace:'{firstname}':"`$clientsdetails.firstname`"|replace:'{country}':"`$clientsdetails.countryname`"} this method allows you to control what tags/information can be outputted in the article(s) - so any Smarty variable.array that the article template has access to, can be shown this way. 3. the nuclear option... stand well back... do not approach... I won't tell you again, get back!! {eval $kbarticle.text} one big reason why eval is not a great idea is that it leaves you wide open to code injection.... I guess you're thinking "cool - I only need to add 'eval' to the template and I can do what I want in the articles...simple" - but it has big security implications. even with {php} disabled in the settings, the above would give you an error and a blank article.... with it enabled, it will show your PHP settings! personally, i'd go with the second option and define whatever tags you need/want to use in the articles and adjust the template (or use a hook if you don't want to touch the template) to replace them with the equivalent Smarty variables... and perhaps only do this for private articles - that way you know they'll be logged in and you won't need to add {if} statements in the code.. although eval could handle those if statements, i'd be looking for alternative methods to eval to do this. I should also add that the above is all tested on a v7.4.1 dev, but I can see no reason why it wouldn't work on v7.1.1 - I haven't used any advanced new Smarty code to do this. 1 Link to comment Share on other sites More sharing options...
cdeese8 Posted December 1, 2017 Author Share Posted December 1, 2017 What a detailed, and magnificent reply - thank you very much! Private article idea is good idea, I did not think of that... ty. Hahaha.. your emojis are great. --- I added #2 option snippet to knowledgebasearticle.tpl - and when I test article, I see duplicate article. Top article displays working variable but strips CSS, the bottom article displays CSS but array doesn't work . I have many template customization's so maybe that is it. Thanks again and thank you very much! yea #3 sounds explosively dangerous, I'm grateful you shared option and HOWTO but I will not do that. Link to comment Share on other sites More sharing options...
brian! Posted December 2, 2017 Share Posted December 2, 2017 16 hours ago, cdeese8 said: I added #2 option snippet to knowledgebasearticle.tpl - and when I test article, I see duplicate article. Top article displays working variable but strips CSS, the bottom article displays CSS but array doesn't work . I have many template customization's so maybe that is it. yes it sounds like it might be - though i'd have to see article code to confirm... the code I wrote shouldn't strip css or even duplicate articles, it's just a simple string replace of A with B. Link to comment Share on other sites More sharing options...
Recommended Posts