Smarty template via string variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    Smarty template via string variable?

    Hello,

    I am trying to work out how to have smarty use a string's contents as the
    display-> template..
    ie:
    $smarty->display($buffe r);

    obviously $buffer isn't a filename, but a smarty template inside a string
    variable. Take this example:

    <snip>
    <?php
    ob_start('ob_ca llback');
    $smarty = new smartyLocal();
    $smarty->assign('var1 ', 'test');
    ob_callback($bu ffer) {
    $smarty->display($buffe r);
    }
    ?>

    <html><head><ti tle>page</title></head>
    <body>
    {$var1}
    </body>
    </html>

    EOF

    What do you guys think? Anyway to do this?


  • Brian

    #2
    Re: Smarty template via string variable?

    I know, that should have been "function ob_callback($bu ffer)", I just meant
    it as an example.


    "Brian" <cpnmscg02 (@) sneakemail.com> wrote in message
    news:pvJEb.4026 10$Dw6.1250589@ attbi_s02...[color=blue]
    > Hello,
    >
    > I am trying to work out how to have smarty use a string's contents as the
    > display-> template..
    > ie:
    > $smarty->display($buffe r);
    >
    > obviously $buffer isn't a filename, but a smarty template inside a string
    > variable. Take this example:
    >
    > <snip>
    > <?php
    > ob_start('ob_ca llback');
    > $smarty = new smartyLocal();
    > $smarty->assign('var1 ', 'test');
    > ob_callback($bu ffer) {
    > $smarty->display($buffe r);
    > }
    > ?>
    >
    > <html><head><ti tle>page</title></head>
    > <body>
    > {$var1}
    > </body>
    > </html>
    >
    > EOF
    >
    > What do you guys think? Anyway to do this?
    >
    >[/color]


    Comment

    • Daniel Tryba

      #3
      Re: Smarty template via string variable?

      Brian <cpnmscg02 (@) sneakemail.com> wrote:[color=blue]
      > Hello,
      >
      > I am trying to work out how to have smarty use a string's contents as the
      > display-> template..
      > ie:
      > $smarty->display($buffe r);
      >
      > obviously $buffer isn't a filename, but a smarty template inside a string
      > variable.[/color]

      Looks like a RTFM to me:


      <q>
      Templates from other sources

      You can retrieve templates using whatever possible source you can access
      with PHP: databases, sockets, LDAP, and so on. You do this by writing
      resource plugin functions and registering them with Smarty.
      </q>

      --

      Daniel Tryba

      Comment

      • Rahul Anand

        #4
        Re: Smarty template via string variable?

        Hi Brian,

        You can use eval to parse your template code before outputting.
        For example if you have a variable $buffer in php file

        $buffer =
        '<html><head><t itle>page</title></head>
        <body>
        {$var1}
        </body>
        </html>';

        $smarty->assign('var1 ', 'test');
        $smarty->assign('buffer ', $buffer);



        You can code your smarty template file as follows

        {eval var=$buffer assign="parsedB uffer"}
        {$parsedBuffer}


        -- Rahul




        "Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<qwJEb.402 615$Dw6.1250605 @attbi_s02>...[color=blue]
        > I know, that should have been "function ob_callback($bu ffer)", I just meant
        > it as an example.
        >
        >
        > "Brian" <cpnmscg02 (@) sneakemail.com> wrote in message
        > news:pvJEb.4026 10$Dw6.1250589@ attbi_s02...[color=green]
        > > Hello,
        > >
        > > I am trying to work out how to have smarty use a string's contents as the
        > > display-> template..
        > > ie:
        > > $smarty->display($buffe r);
        > >
        > > obviously $buffer isn't a filename, but a smarty template inside a string
        > > variable. Take this example:
        > >
        > > <snip>
        > > <?php
        > > ob_start('ob_ca llback');
        > > $smarty = new smartyLocal();
        > > $smarty->assign('var1 ', 'test');
        > > ob_callback($bu ffer) {
        > > $smarty->display($buffe r);
        > > }
        > > ?>
        > >
        > > <html><head><ti tle>page</title></head>
        > > <body>
        > > {$var1}
        > > </body>
        > > </html>
        > >
        > > EOF
        > >
        > > What do you guys think? Anyway to do this?
        > >
        > >[/color][/color]

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: Smarty template via string variable?

          "Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<pvJEb.402 610$Dw6.1250589 @attbi_s02>...[color=blue]
          > Hello,
          >
          > I am trying to work out how to have smarty use a string's contents as the
          > display-> template..
          > ie:
          > $smarty->display($buffe r);
          >
          > obviously $buffer isn't a filename, but a smarty template inside a string
          > variable. Take this example:
          >
          > <snip>
          > <?php
          > ob_start('ob_ca llback');
          > $smarty = new smartyLocal();
          > $smarty->assign('var1 ', 'test');
          > ob_callback($bu ffer) {
          > $smarty->display($buffe r);
          > }
          > ?>
          >
          > <html><head><ti tle>page</title></head>
          > <body>
          > {$var1}
          > </body>
          > </html>
          >
          > EOF
          >
          > What do you guys think?[/color]





          --
          http://www.wikipedia.org/wiki/P.A.Sangma - Yet-another Mahatma
          Email: rrjanbiah-at-Y!com

          Comment

          Working...