Jump to content

Include PHP Code in Template


readywire

Recommended Posts

I am trying to add an RSS feed to my WHMCS client area.

 

I came across RSS2HTML, a script that pulls RSS data and converts it to HTML. As you can see, it's working just fine on its own:

 

https://secure.readywire.com/rss/rss-blog.php

 

Now, how can I incorporate this php page (rss-blog.php) into a WHMCS template?

 

Someone on the forum suggested that I do the following:

 

{php}

include('/path/to/file.php');

{/php}

 

The Smarty documentation suggested that I try this:

{include file='/path/to/file.php'}

 

Neither seem to be working and I can't find anything in my Apache error logs to tell me why it's not working.

 

Thanks for your help!

Link to comment
Share on other sites

To include a php file in your template then the included file is relative to your templates directory only.

eg.. from your example {include_php file="/rss/rss-blog.php"}

if you have whmcs in a directory (say whmcs) and your file there is in the rss directory in your public_html. The correct way is this {include_php file="../../rss/rss-blog.php"}

or you need to specify the full path {include_php file="/home/user/public_html/rss/rss-blog.php"}

 

Hope that helps

Link to comment
Share on other sites

  • 1 month later...

I have a similar problem, I am using a PHP include file to standardise my top menu, which works well with the common PHP web pages but wont work with WHMCS Templates. I have tried all the following:

{include file='../inc/menu_box-top.php'}

 

{include_php file='../inc/menu_box-top.php'}

 

{insert name='../inc/menu_box-top.php'}

 

{php}
include ('../inc/menu_box-top.php');
{/php}

 

To insert this PHP include file.

 

<div id="topMenuBox">
<table width="256" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td width="80">
			<a href="index.php"><img src="images/topMenu_03.jpg" alt="Home" width="80" height="39" border="0" /></a>
		</td>
		<td width="84">
			<a href="client/clientarea.php"><img src="images/topMenu_04.jpg" alt="Clients Log-In" width="84" height="39" border="0" /></a>
		</td>
		<td width="92">
			<a href="smf/index.php"><img src="images/topMenu_05.jpg" alt="Forum" width="92" height="39" border="0" /></a>
		</td>
	</tr>
</table>
</div>

 

All I have so far is the alternate text with hyperlinks (at least we know I have the right path ;))

 

Anyone know a way to include the HTML stuff in a template and still maintain a common point of change for all code?

Link to comment
Share on other sites

It only shows the alt text as a hyperlink, not the images ... Doh!

 

The path for the images is not correct... :oops:

 

I'll try using absolute paths in the PHP include file.

 

Thanks very much for the assist. It's always the way, isn't it? As soon as you ask someone else to have a look, you find the mistake and it is always a simple one. :roll:

 

Still, it is 2:52AM here. ;) But it is working now!! It has introduced another path problem but I look at that in about 8 hours time.

 

Thanks again Bear,

 

Cheers,

 

Mike

Link to comment
Share on other sites

They're in /home/public_html/images and WHMCS is in /home/public_html/clients but the rest of the sites code is in /home/public_html, hence the problem using a common file.

 

Is there a better way to access all three?

 

Cheers,

 

Mike

Link to comment
Share on other sites

Use {include_php file="../../inc/menu_box-top.php"}

 

Including files into a template is relative to the templates directory (not the whmcs root)

 

and change your php file to this (using paths relative to the doc root)

[color=#000000][color=#007700]<[/color][color=#0000bb]div id[/color][color=#007700]=[/color][color=#dd0000]"topMenuBox"[/color][color=#007700]> 
   <[/color][color=#0000bb]table width[/color][color=#007700]=[/color][color=#dd0000]"256" [/color][color=#0000bb]border[/color][color=#007700]=[/color][color=#dd0000]"0" [/color][color=#0000bb]cellpadding[/color][color=#007700]=[/color][color=#dd0000]"0" [/color][color=#0000bb]cellspacing[/color][color=#007700]=[/color][color=#dd0000]"0"[/color][color=#007700]> 
       <[/color][color=#0000bb]tr[/color][color=#007700]> 
           <[/color][color=#0000bb]td width[/color][color=#007700]=[/color][color=#dd0000]"80"[/color][color=#007700]> 
               <[/color][color=#0000bb]a href[/color][color=#007700]=[/color][color=#dd0000]"/index.php"[/color][color=#007700]><[/color][color=#0000bb]img src[/color][color=#007700]=[/color][color=#dd0000]"/images/topMenu_03.jpg" [/color][color=#0000bb]alt[/color][color=#007700]=[/color][color=#dd0000]"Home" [/color][color=#0000bb]width[/color][color=#007700]=[/color][color=#dd0000]"80" [/color][color=#0000bb]height[/color][color=#007700]=[/color][color=#dd0000]"39" [/color][color=#0000bb]border[/color][color=#007700]=[/color][color=#dd0000]"0" [/color][color=#007700]/></[/color][color=#0000bb]a[/color][color=#007700]> 
           </[/color][color=#0000bb]td[/color][color=#007700]> 
           <[/color][color=#0000bb]td width[/color][color=#007700]=[/color][color=#dd0000]"84"[/color][color=#007700]> 
               <[/color][color=#0000bb]a href[/color][color=#007700]=[/color][color=#dd0000]"/client/clientarea.php"[/color][color=#007700]><[/color][color=#0000bb]img src[/color][color=#007700]=[/color][color=#dd0000]"/images/topMenu_04.jpg" [/color][color=#0000bb]alt[/color][color=#007700]=[/color][color=#dd0000]"Clients Log-In" [/color][color=#0000bb]width[/color][color=#007700]=[/color][color=#dd0000]"84" [/color][color=#0000bb]height[/color][color=#007700]=[/color][color=#dd0000]"39" [/color][color=#0000bb]border[/color][color=#007700]=[/color][color=#dd0000]"0" [/color][color=#007700]/></[/color][color=#0000bb]a[/color][color=#007700]> 
           </[/color][color=#0000bb]td[/color][color=#007700]> 
           <[/color][color=#0000bb]td width[/color][color=#007700]=[/color][color=#dd0000]"92"[/color][color=#007700]> 
               <[/color][color=#0000bb]a href[/color][color=#007700]=[/color][color=#dd0000]"/smf/index.php"[/color][color=#007700]><[/color][color=#0000bb]img src[/color][color=#007700]=[/color][color=#dd0000]"/images/topMenu_05.jpg" [/color][color=#0000bb]alt[/color][color=#007700]=[/color][color=#dd0000]"Forum" [/color][color=#0000bb]width[/color][color=#007700]=[/color][color=#dd0000]"92" [/color][color=#0000bb]height[/color][color=#007700]=[/color][color=#dd0000]"39" [/color][color=#0000bb]border[/color][color=#007700]=[/color][color=#dd0000]"0" [/color][color=#007700]/></[/color][color=#0000bb]a[/color][color=#007700]> 
           </[/color][color=#0000bb]td[/color][color=#007700]> 
       </[/color][color=#0000bb]tr[/color][color=#007700]> 
   </[/color][color=#0000bb]table[/color][color=#007700]> 
</[/color][color=#0000bb]div[/color][color=#007700]>  [/color][/color]

If you have seo enabled in whmcs (using base href) then you will need to change the paths in the php file to the full url eg.. https://domain.com/images/topMenu_03.jpg

 

Link to comment
Share on other sites

I thought {include_php} was being depreciated. :?: Otherwise it seemed like the better option, given that it can be cached and {include} can't according to Smarty Net.

 

I understand that the files are relative to the WHMCS template directory but I also use the same file as an include for the non-template web pages, which is a different directory again, closer to the root.

 

I have a feeling I should be using a variable of some kind but my PHP, HTML, Smarty "code", etc knowledge is quite limited.

Link to comment
Share on other sites

  • 2 years later...

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