1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php code in tpl file

Discussion in 'PHP' started by floriano, Aug 21, 2016.

  1. #1
    Hello,

    I want to insert a little code php in .tpl file (I don't use smarty template).
    I searching in google some example with: {literal}{/literal}, but I cannot replace my code.

    This is my code:
    
    require_once("functions.php");
    $some_name = $_GET['v'];
    echo  '<input type="hidden" id="current_name" value="'. $some_name .'">';
    
    Code (markup):
    I try but I can't do it, I don't know hou use: " and ' !

    Thanks in advance for any help !!
     
    floriano, Aug 21, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You say you're not using smarty - then what are you using? Most examples are for smarty .tpl-files, and might not work with other templating engines.

    However, wrapping your code with either {php}{/php} or {literal}{/literal} should work. The code you presented seems to be correct PHP, and should work as long as the php is actually interpreted.
     
    PoPSiCLe, Aug 21, 2016 IP
  3. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #3
    Sorry, I see now my website used smarty...

    I try like this, but don't work:
    
    {literal}require_once("functions.php");{/literal}
    {literal}$some_name = $_GET['v'];{/literal}
    echo  {literal}'<input type="hidden" id="current_name" value="'. $some_name .'">';{/literal}
    
    PHP:
    I don't know how to do.

    If some one can help me !

    Thanks !
     
    floriano, Aug 21, 2016 IP
  4. Again3

    Again3 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    I never used that, but have you tried this?

    
    {literal}
    require_once("functions.php");
    $some_name = $_GET['v'];
    echo '<input type="hidden" id="current_name" value="'. $some_name .'">';
    {/literal}
    
    PHP:
     
    Again3, Aug 21, 2016 IP
  5. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #5
    @Again3 , don't work. I was try it.
     
    floriano, Aug 21, 2016 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Did you try to change {literal} to {php}?

    And which version of Smarty are you using? Since that might change what works and not. You can also change the default rendering of PHP in the Smarty config, but that might not work either, depending on what version you're running.
     
    PoPSiCLe, Aug 21, 2016 IP
  7. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #7
    I was try same this, but don't work....

    
    {include file='some_functions.php' p="index"} {php} $some_name = $_GET['v']; echo '<input type="hidden" id="current_name" value="'. $some_name .'">'; {/php}
    
    Code (markup):
    Anyone can help write code ?
     
    floriano, Aug 22, 2016 IP
  8. Abdul Ali Khan

    Abdul Ali Khan Member

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    33
    #8
    There is no need to change your code. You can simply allow PHP script to run in .tpl files by adding this line to your .htaccess file (provided your server supports one):
    AddType application/x-httpd-php .tpl
    Code (markup):
    This should allow PHP code to execute in all .tpl files in the directory. Remember to add the PHP start and end tags (<?php & ?>) before and after your code. Check out this article to learn more about the .htaccess file:
    https://blog.cocashcreators.com/a-guide-to-the-htaccess-file/
     
    Abdul Ali Khan, Jun 27, 2017 IP
  9. z13

    z13 Member

    Messages:
    12
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    33
    #9
    What kind of CMS do you use? The right answer depends on it.
     
    z13, Jul 23, 2017 IP