Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/03/2014, 16:27
Avatar de berkeleyPunk
berkeleyPunk
 
Fecha de Ingreso: febrero-2013
Ubicación: México :C
Mensajes: 565
Antigüedad: 11 años, 2 meses
Puntos: 22
Pregunta Cómo hacer plantilla con Flexy template engine?

Cómo estamos todos!


Me bajé una tienda virtual llamada x-Cart. Si uno quiere hacer su propio template, x-Cart nos dice en su tutorial que utilicemos su clase PHP llamada templater, la cual está basada en Flexy template engine.

O sea, que primero tengo que aprender a usar esto último antes de comenzar con la clase propia de la tienda x-Cart.

No he encontrado mucha documentación dirigida a principiantes. En este sitio hay un ejemplo BASICO que no logro hacer funcionar.

Si alguien ya tiene experiencia en esto, igual y puede echarme una mano. Mi problema es que no logro hacer una plantilla.

Datos con los que trabajo:
1. Mac OS X 10.8
2. Pear

Bajé el Flexy y trabajo con los siguientes documentos PHP. Cuando ejecuto el primero, no se crea la plantilla y aparece en pantalla: Could not find Template plantilla.html in any of the directories, como si el archivo plantilla.html no se encontrara en la ruta especificada. Y sí, ahí está!

Primer archivo:
Código PHP:
<?php

/* configure the application - probably done elsewhere */
require_once 'flexy/HTML/Template/Flexy.php';
require_once 
'PEAR.php';

$options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
$config parse_ini_file('example.ini',TRUE);
$options $config['HTML_Template_Flexy'];


/* the page controller class */

class controller_test 
{

    var 
$template "plantilla.html"// name of template
    
var $title;                  // this relates to {title};
    
var $numbers = array();      // this relates to {numbers} , used with foreach
    
var $anObject;

    var 
$elements = array();      // this is where the elements are stored

    /* start section - deals with posts, get variables etc.*/

    
function controller_test() 
    {
        
$this->start();
        
$this->output();
    }


    function 
start() 
    {
        
// the title
        
$this->title "Hello World";

        
// store an object.
        
$this->anObject = new StdClass;

        
// assign a value to a member.
        
$this->anObject->member 'Object Member';

        
// if you need form elements - you have to include them.
        
require_once 'flexy/HTML/Template/Flexy/Element.php';

        
// create an HTML Element for the form element.
        
$this->elements['input'] = new HTML_Template_Flexy_Element;

        
// assign a value to it
        
$this->elements['input']->setValue('Hello');


        for (
$i 1;$i5;$i++) {
            
$this->numbers[$i] = "Number $i";
        }
    }

    
/* output section - probably best to put this in the default_controller class */

    
function output() {
        
$output = new HTML_Template_Flexy();
        
$output->compile($this->template);
        
$output->outputObject($this,$this->elements);
    }


    function 
someMethod() {
        return 
"<b>Hello From A Method</b>";
    }



}

/* the page controller instantaation - probably done with a factory method in your master page controller class */

new controller_test();

?>

Segundo archivo, llamado ejemplo.html:
Código PHP:
<html>
  <head>
    <title>{title}</title>
  </head>
  <body>
  <H1>{title}</H1>



    <form name="form">
      <table>
        <tr>
          <td>
           <?php /*  this will be merged with the date in the  $element['input']  object*/ ?>
  
            Input Box: <input name="input">
          </td>
        </tr>
  
        <?php /*  note here the use for flexy:foreach as an attribute value */ ?>
  
        <tr flexy:foreach="numbers,number,string">
          <td>
  
        <?php /*   note here the use for flexy:foreach as an attribute value */ ?>
  
            <a href="mypage.html?id=%7Bnumber%7D">{string}</a>
          </td>
        </tr>
      </table>
    </form>




    <?php /*   there is some limited support for array access */ ?>

      this is number 2 : {numbers[2]}


    <?php /*  note that full stops separate object and variables or methods */ ?>

      This is a {anObject.member}

    <?php /* you can call methods of the object */ ?>

      {someMethod()}

    <?php /* by default everything is htmlspecialchar escaped use the modifier :h to prevent this. */ ?>

      {someMethod():h}
    
  </body>
</html>

<?php /*  I've used php for comments here as HTML comments didnt work when generating the
manual .. - you dont have to use them - it has nothing to do with the template engine */ 
?>
Este segundo código está en el archivo plantilla.html (que no sé por qué es HTML si contiene PHP).

El archivo example.ini al que se hace referencia no sé dónde obtenerlo.




Saludos cordiales!


Última edición por berkeleyPunk; 28/03/2014 a las 16:34