[Problem] Using variables in PHP
  • Hello,

    I read this example in manuals:

    {{ assign var="profile_email" value=`$gimme->comment->reader_email` }}
    {{ php }}
    $profile_email = $this->get_template_vars('profile_email');
    print $profile_email;
    {{ /php }}


    My problem is that i want to assign {{ uri options="article" }} to a variable.

    I want the SEF url of an article to be assigned to a variable to use it in a Facebook application.

    If i use $gimme->article->url_name - i get artcle number (ID).

    Please, help. Thank you.
  • 8 Comments sorted by
  • Try the following code inside the {{ php }} tag:
        foreach ($this->plugins_dir as $dir) {
            $filePath = $dir . '/function.url.php';
            if (file_exists($filePath)) {
                include($filePath);
            }
        }
        $url = smarty_function_url(array('options'=>'article'), $this);
        echo $url;

  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    put {{ uri options="article" }} inside facebook code where should be placed article url
  • The facebook code is between {{ php }} {{ /php }} tags. Will it work?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    try ....{{ /php }}{{ uri options="article" }}{{ php }}....
  • Ok, here is a piece of code that i am trying to get working:

    {{ list_articles length="1" ignore_issue="true" ignore_section="true" order="bypublishdate desc" constraints="type is aspecte" }}
    {{ php }}
    require_once('facebook-platform/php/facebook.php');

    function get_yar_likes($url_like)
    {
        $adresa = "https://api.facebook.com/method/fql.query?query=select like_count from link_stat where url="".$url_like."%22";
        $valoare = @simplexml_load_file($adresa);
        return ($valoare) ? ucwords(strtolower($valoare->link_stat->like_count)) : false;
    }

    $url = {{ /php }}{{ uri options="article" }}{{ php }};

    $aspect1 = get_yar_likes($url."&vot=1");
    $aspect2 = get_yar_likes($url."&vot=2");

    .....
    {{ /php }}
    {{ /list_articles }}

     Unfortunately, the sollution you suggested did not work. Any other idea? Please...
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    see rendered html code. At least you have missed "
  • Mugur, thank you. Works like a charm.
  • Reply to @Mugur+Rus:

    Mugur, will this code work on Newscoop 4? If not, what's the new code for NC4, please?

    Thank you.