Jump to content

Adding PHP code


Aviationguy

Recommended Posts

I have been reading up on PHP code and wanted to add a hit counter to my page. I found some examples of code so I tried adding it to main.php and nothing happened. I tried others and nothing so I put in this bare bones statement:

<?php
$counterVal=1501;
echo "You are visitor number $counterVal to this site";              
?>   

Nothing fancy but also nothing on my page.  My question is, why can't I add this code and see the result on my page?

I appologize if this is not appropriate for this forum.  If it is, just delete me.

Link to comment
Share on other sites

You have a good understanding of PHP pages. However, CubeCart uses Smarty as a template rendering engine, and the skin templates - although suffixed with .php - never actually gets processed by PHP. Or anything at all, actually, other than Smarty*.

Smarty will 'compile' the template and in so doing, will ignore everything that is not tightly enclosed within braces ({ and }). The result is sent directly out. Thus, the web browser, seeing <?php whatever ?> in the HTML code will do nothing with this as this is not a valid HTML markup tag.

So, when using Smarty to render templates, one needs to give to Smarty the value of a variable, and code the variable into the template.

*One can ask the web server to deliver the template directly (www.mystore.com/skins/foundation/templates/main.php). Since the templates do have the suffix .php, the web server will first send the template file to PHP for processing. In this scenario, the PHP code will be executed.

 

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.

×
×
  • Create New...