Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Display HTML Code
  • I have controller that strore in database html code (templates, blocks)
    eg:
    <b>test</b> The problem is that I cant see the BOLD result of <b>test</b> when I get this record from database and display on the page. I see <b>test</b> instead of BOLD "test"
  • Look at the view forge method in docs:
    /docs/classes/view.html
    You want to set the filter parameter to false to prevent forge() from encoding the html tags
    for instance:
    $view = View::forge('path/to/view', $data, false);
    
  • I cant do $view = View::forge('path/to/view', $data, false); I use template controller:
    public function action_index($slug) {
    $page = Model_Page::find()->where('slug', $slug)->get_one();
    $this->template->title = $page->title;
    $this->template->content = $page->content;
    } Any other solutions ?
  • Look at your app/config.php file
    find this parameter, near the bottom:
    security.auto_filter_output
    Set it to false to turn off view output encoding (htmlentities).
    This is dangerous, because it is a global parameter and will turn off encoding for all view output. You other option may be to use the after() method and turn off the encoding on a controller-by-controller level.
    I haven't run into this need, so I've not tested it.
  • How to use just for this: $this->template->content = $page->content; ? I need to render page content that stored with html in database
  • If you are using Fuel's rendering system. it will use htmlentities to encode the html which you send to it. This is controlled by the config parameter mentioned above.
    I don't know how you are rendering your views to the browser, but it obviously is being encoded, which means it probably is going through Fuel's rendering system. Find the code in the template system (I don't use it and cannot tell you where to look), it will probably contain a call to the view::forge() method.
    I would NOT change the core code, but you can probably override it by making a custom version in which you can set the $filter parameter (as mentioned above).
    Sorry I cannot be more specific, as I said, I don't use a template system.
  • >>If you are using Fuel's rendering system.
    It makes no difference... 1) I need to save html code to database(Html pages, Html templates etc...). I store it as is <b>test</b>. or I am wrong ?
    2) I need to get this HTML and render it. for eg <b>test</b> must be bold
    3) It helps only 'output_filter' => array(), and then manualy I can escape if I need some variables. I am using Twig.
    {{content}} Would be bold "test" as I want)
    {{content|e}} Would be <b>test</b>
    http://twig.sensiolabs.org/doc/filters/escape.html Is that normal practice ?
    1) Set 'output_filter' => array(),
    2) And escape all vars in template, except fro eg content ?
  • By default Fuel will escape all variables going to a view. This is done by the View class, no matter what template solution you use. And it is done before the variables are passed on to the template engine. The the properties approach is identical to calling set() on the View object, it will escape when the auto_filter is active. Which it is by default. You can do several things:
    // switch the autofilter of for all variable assignments (bad idea if you want a secure app)
    $viewobject->auto_filter(false);
    
    // assign a variable with filtering disabled
    $viewobject->set('variable', $value, false);
    
    // or use this, which is an alias
    $viewobject->set_safe('variable', $value);
    
  • I dont have view object. I have Template Controller
    $this->template->content = $page->content; Create a view for this variable ? $this->template->content = View::forge('page.twig')->set('content', $page->content, false);
    It works, but maybe other solutions ?
  • I Just discovered that $this->template is view object :) This works fine $this->template->set('content', $page->content, false);

Howdy, Stranger!

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

In this Discussion