SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with Google Optimizer and PHP / Smarty Templates

    Hello all,

    We are looking for a bit of guidance. We are using a php / smarty based ecommerce software, and are trying to integrate it with the google optimizer, but are running into a couple of problems.

    We have set everything up correctly, but when we input smarty tags into the optimizer like this:

    Code:

    {include file="modules/Bestsellers/menu_bestsellers.tpl" }



    They end showing the literal version of this:
    "{include file="modules/Bestsellers/menu_bestsellers.tpl" }"

    To get the optimizer to show different results you have to wrap the code you want to change in the following:

    <script>utmx_section("literal categories")</script>
    </noscript>

    I have tried wrapping this in {literal}{/literal} but that did not work, I also tried wrapping the call in {/literal}{/literal}, but that did not work either.

    Any help with this would be greatly appreciated.

  2. #2
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try to backslash escape the quotes :

    Code:
    {include file=\"modules/Bestsellers/menu_bestsellers.tpl\" }
    I'm not sure if this pertains to smarty templating, but I have read that all quotes have to be escaped.

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that did not work. Any other suggestion?

  4. #4
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm..

    Are there scripts being called / ran in the tpl file? Did you wrap them? {literal}{/literal}

  5. #5
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sgt_cory View Post
    hmm..

    Are there scripts being called / ran in the tpl file? Did you wrap them? {literal}{/literal}
    Yes, I did. The optimizer seems to just output literally.... I did do some testing though, and you can input javascript into it. So I think I could call an external javascript file / source, but I am not 100% sure how to put the smarty variable into the javascript, and get it to work properly.

  6. #6
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah - it's the sequence, meaning it is being read literally. So we need a way to execute the smarty template which is invoked with the curly bracket - which I suspect was not approached by google so far (another immediate bracket after the literal). So - did you already try escaping the curly brackets and quotes :

    \{include file=\"modules/Bestsellers/menu_bestsellers.tpl\" \}

    without using literal and with, meaning try it both ways. Let's see what that does?

  7. #7
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sgt_cory View Post
    yeah - it's the sequence, meaning it is being read literally. So we need a way to execute the smarty template which is invoked with the curly bracket - which I suspect was not approached by google so far (another immediate bracket after the literal). So - did you already try escaping the curly brackets and quotes :

    \{include file=\"modules/Bestsellers/menu_bestsellers.tpl\" \}

    without using literal and with, meaning try it both ways. Let's see what that does?
    Showed up literally for both methods: \{include file=\"modules/Bestsellers/menu_bestsellers.tpl\" \}

  8. #8
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe it would work if I called it from a javascript file. The optimizer accepts javascript fine. I just dont know how to execute the smarty variable within a javascript file.

    Something like:

    <script type="text/javascript" src="{$SkinDir}/customer/main/execute_smarty.js"></script>

  9. #9
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah - now that I posted that I see why it wouldn't work. Hmmm. You could always change your delimiter, but that doesn't solve the real problem. I'll keep my eyes open and think on this for a bit.

    EDIT :

    I just read your post. That may work, but I think this fellow found a better solution. Create a new class that will let you change the delimiters on the fly, right before your template calls :

    class mySmarty extends Smarty
    {
    function mySmarty() {
    $this->left_delimiter='{{';
    $this->right_delimiter='}}';
    }
    }

    (Of course using a completely different delimiter)

    Smarty class

    And more reading here : Smarty escaping

  10. #10
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would this have to be site wide?

  11. #11
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not unless all of your pages are set up the same , otherwise - yes it would be sitewide. But I assume that you would still have to call your javascript file as well on everypage. So You could either invoke the class from a setup file or class file if you have one, or use javascript.

    I wish I had more experience with Smarty - I'd be able to offer an opinion on which method to use. My experience tells me that the class would be more useful, simply because you would have to continually add to your Javascript calls if you wanted to add anymore templates.

  12. #12
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sgt_cory View Post
    Not unless all of your pages are set up the same , otherwise - yes it would be sitewide. But I assume that you would still have to call your javascript file as well on everypage. So You could either invoke the class from a setup file or class file if you have one, or use javascript.

    I wish I had more experience with Smarty - I'd be able to offer an opinion on which method to use. My experience tells me that the class would be more useful, simply because you would have to continually add to your Javascript calls if you wanted to add anymore templates.
    I think the site is too complicated to do that. Its not your typical site. It is a base ecommerce site with one database, that essentially feeds product and order information to smaller sites. To do something like this site wide would be a laborious task. In addition there are many encoded files, which cannot be adjusted. So it is literally out of the question. If I could change it for that one section, that would be fine. I think the javascript is the best way to go for this scenario, just not at all sure how to do it, as I am not a programming expert in any regards, just know how to edit the templates for design changes and some modest html stuff, real beginner stuff, but I can conceptualize what is happening.

  13. #13
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just thought of two more ideas - worth a shot and I'll give it a rest for the night ;-) :

    {literal}\{{\literal}include file=\"modules/Bestsellers/menu_bestsellers.tpl\" {literal}\}{/literal}

    and did you try :

    {ldelim}include file=\"modules/Bestsellers/menu_bestsellers.tpl\"{rdelim}
    or
    {ldelim}include file=\"modules/Bestsellers/menu_bestsellers.tpl\"{rdelim}
    or
    {literal}
    {ldelim}include file=\"modules/Bestsellers/menu_bestsellers.tpl\"{rdelim}{/literal}

    i'm stumped! I can't stand stumped ..lol

    Sincerely, I tried, and I'll keep you in my thoughts as I go to work tomm, and see what I can come up with.

    EDIT

    I believe this is how to do your Javascript call:

    document.write('{ldelim}include file="modules/Bestsellers/menu_bestsellers.tpl"{rdelim}')

    That goes in your Javascript file along with whatever else you require, and you invoke it like you pointed out earlier, by calling the file you made and named :

    <script type="text/javascript" src="{$SkinDir}/customer/main/execute_smarty.js"></script>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •