PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] How can helper function render a template manually, and echo it

 February 22, 2022     cakephp-3.0, helper, helpers     No comments   

Issue

I have a Helper as the following:

 class IconHelper extends Helper{

     public function showList(){
         //render a template from ctp file
         $template = loadFromTemplate('path/to/my.ctp');
     }
 }

I want a function to render a .ctp template and return it .


Solution

I found View Cells:

In the case that your content can is small inline template, then you can use the Helper, as following:

 class IconHelper extends Helper{

 public function show($icon){

    $template = '<a class="btn btn-default">'.$icon.'</a>';

    return $template
 }

but in the case when the content is saved in a template CTP file, the best practice is to use the View Cells:

 //helper class
 class IconListCell extends Cell{
 public function display($icon){
      //script .....
       $this->set(copmat('icon));
   }
 }
 //file: src/Template/Cell/show.ctp
 <a class="btn btn-default" style="font-size: 40px;width: 70px;">
     <span class="'.$icon.'" id="icon-value-button" data-pack="default">/span>
 </a>


Answered By - Eymen Elkum
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing