Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Inline php in the view or smrty-like placeholders?
  • I have another question or just need a estimation from you. The last few month (years) I worked with CI I always used smarty-like placeholders ({something}) to put my data from the controller into the view via:
    $data['something'] = $this->anyfunction();   //data for placeholder {something}
    $this->parser->parse("my_view", $data);
    

    A other way I always saw in the Fuel Docs are inline PHP in the view (I also know that from CI Doc). I never did this, because I don´t like it to have PHP code in my view. Normally it must be fully separated.
    But with inline php you can do things in your controller like this just to set a variable (inline PHP in the view):
    $this->title = "My current title";
    

    Works this also with placeholders in the Views?
    And what would you recommend? It´s really hard for me at the moment to find the way what is "best" (I know all roads lead to Rome, but just give me your ideas / suggestions)! Thanks! :)
  • What a pitty. Would be really nice to have such a placeholder template-engine like CI. No one wants to have php-code in his templates. Templates are an abstraction to divide html and php code.
  • Thanks. This will make some things handling templates much easier. What I am searching for (smarty placeholders) are these "simple tags" they are speaking about? And: For now I have copied the CI parser class-functions with some modifications in one of my classes ... works for now. I ask myself: If I would like to write something with fuelphp to make a special functionality available for the community. It would be a core-class or a module?
    In CI it would be a library or a helper (or a plugin). Sorry for comparing so much with CI. :)
  • I´m a little bit confused. It is even possible to use placeholders in brackets and fill them with the render() method? View:
    This is some text: {placeholder}
    
    Controller:
    $this->data['placeholder'] = "foo bar";
    $this->render("my_view", $this->data);
    

    I ask, because it does not work at the moment, but I thought it would work (and I thought I saw it somewhere in the doc). It is also used in the template welcome/index view which is used after the installation e.g.:
    {exec_time}
    
  • There is no such possiblitify for placeholders atm, I think Jelmer wanted to introduce Dan's SimpleTags, but not ready yet I htink... And about {exec_mem}, it's only a string replace :( look into core\classes\fuel.php, line 185
    // TODO: There is probably a better way of doing this, but this works for now.
      $output = \str_replace(
        array('{exec_time}', '{mem_usage}'),
        array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
        $output
      );
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion