How to insert view into another view? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: How to insert view into another view? (/showthread.php?tid=63791) Pages:
1
2
|
How to insert view into another view? - Kostia - 12-10-2015 Hi! Sorry for my english. I just started learning framework, and I have a question: How to insert view into another view? In documentation: PHP Code: <?php But I wish that there was a basic template, which would connect their content file for each page Example: PHP Code: <?php How to do it correctly? Thank you! RE: How to insert view into another view? - edwade3 - 12-10-2015 They way achieve this is to have a main view that is loaded (placed in the root of the views folder called main_view.php). In this file, I have a line as follows: PHP Code: $this->load->view($view,$data); In my controller I then do the following: PHP Code: $data['view'] = 'users/login'; This then loads your main view and your subview and the $data variables are available to all the views. RE: How to insert view into another view? - rakeshshrs - 12-10-2015 This should work: PHP Code: <?php $this->load->view('file_name');?> RE: How to insert view into another view? - nasser.man - 12-10-2015 you can get output of view using this command: $output_of_view1 = $this->load->view('path_to_view1" , $data , true); then in view2 , you can echo $output_of_view1, remember to send $output_of_view1 to view2, $data['view1'] = $output_of_view1; $this->load->view('path_to_main_view' , $data ); i hope this helps, RE: How to insert view into another view? - cartalot - 12-10-2015 so for example a controller that shows blog pages in your controller constructor - define the folder your blog view files are in and the template name PHP Code: // the folder your content files are in in a method when you are ready to call some views PHP Code: $data['content01'] = 'search_articles'; the template itself views/blog_template.php PHP Code: // opening html etc that is generic to website RE: How to insert view into another view? - ozzy mandiaz - 12-15-2015 i am thinking (its a dangerous prospect, I know) that cartalot's solution is the simplest in that you simply load your views in succession. being a relative neophyte to the CI 3, I couldn't imagine doing this any differently in either 2 or three. that is, unless I have completely missed the intent or goal of Kostia's question. RE: How to insert view into another view? - webcomfort - 12-15-2015 I think, that you need simple helper, like this: PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Load this helper or autoload it. And call function from your view: PHP Code: <?php echo @view('my_view', array('param'=>'pam-pam')); ?> RE: How to insert view into another view? - jaynarayan - 12-17-2015 There are some template libraies available for ci. You can try them. Or roll out your own. Search google for how to create template library in ci. Even If you dont need template system just look at code. you will learn use full tricks RE: How to insert view into another view? - skunkbad - 12-17-2015 (12-10-2015, 03:13 AM)nasser.man Wrote: you can get output of view using this command: Yes, the third parameter of Load::view() is the answer. I don't see any reason to use anything else. Most websites are going to have a main template, which pages that are generated as content inserted into the main template. Setting the third parameter of view() to TRUE ensures that the view is not output, but returned. RE: How to insert view into another view? - Kostia - 01-09-2016 Thank you all for answers! I wrote my code using the third parameter of Load::view('path_to_view1" , $data , true) It looks like this: Controller PHP Code: <?php View template.php Code: <!doctype html> Thank you! |