ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Embeded PHP Snippet Code in not working

August 13, 2009 12:02pm

Subscribe [2]
  • #1 / Aug 13, 2009 12:02pm

    netlinkblueEE

    39 posts

    Hi,

    I have a PHP function. iam calling this function in all my templates. so i created templates goup for php pages called “snipets” and created one page under snipets called “countryurl” the code is below for the page is

    <?php
    
    function country_url(){
    $u = explode('/', $_SERVER['REQUEST_URI']); 
    $u[2]; 
    $x=$u[2];
    echo $x;
    }
    
    ?>


    now iam embedding this template on my index page template the code is

    {embed="snipets/countryurl"}
    <html>
    <head>
    </head>
    <body>
    <a href="<?php country_url();?>">
    </body>
    </html>


    iam trying to execute my function through my index template but this is not woking.


    if i put the code in the templates it working like this

    <?php
    
    function country_url(){
    $u = explode('/', $_SERVER['REQUEST_URI']); 
    $u[2]; 
    $x=$u[2];
    echo $x;
    }
    
    
    <html>
    <head>
    </head>
    <body>
    <a href="<?php country_url();?>">
    </body>
    </html>

    Help needed.

  • #2 / Aug 17, 2009 7:28am

    silenz

    1651 posts

    I’m afraid this is not how things work.
    When you embed the template it gets executed seperately. So you don’t have access to the function from the main template.

    That said, what is the function supposed to return? The first url-segment?

  • #3 / Aug 17, 2009 7:45am

    netlinkblueEE

    39 posts

    hi,

    Thanks for your reply. please tell me how can i make a common php snippet code such that it can be used on all the templates.

    yes, the above function return the url segment.

    Thanks.

  • #4 / Aug 17, 2009 7:57am

    silenz

    1651 posts

    please tell me how can i make a common php snippet code such that it can be used on all the templates.

    That sounds more like a job for a plugin instead of an embed with some PHP.

    yes, the above function return the url segment.

    Wouldn’t {segment_1} achieve the same?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases